<html>
<head><meta charset="utf-8"><title>Extract callgraph of a crate · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html">Extract callgraph of a crate</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="216012979"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216012979" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216012979">(Nov 08 2020 at 16:08)</a>:</h4>
<p>Hello, hello!<br>
In order to have a good understanding of an unknown codebase, I would like to be able to interactively visualize the whole call graph. I searched before, and didn't found one. But since I have some free time, I could build it myself! The pipeline is relatively simple:</p>
<ul>
<li>extract the fully qualified name of all functions/methods declared in the crate.</li>
<li>create an hyperlink to the documentation of said function.</li>
<li>extract from the AST/IR/…? the fully qualified name of all called functions. Ideally also extract all Fn, Trait parameters and other means to inject function dependencies<ul>
<li>create a graph of dependencies, export it with graphviz</li>
<li>displays the graph</li>
</ul>
</li>
</ul>
<p><span class="user-mention" data-user-id="232545">@Joshua Nelson</span> told me that I could write a <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast/visit/trait.Visitor.html"><code>Visitor</code></a> that only looks at functions. He also told me that I can take a look at <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_interface/util/struct.ReplaceBodyWithLoop.html"><code>ReplaceBodyWithLoop</code></a> as an example. More specifically, apparently what I need is <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyCtxt.html#method.body_owners"><code> tcx.hir().krate().body_ids</code></a> to be able to look at each function body one at at time. </p>
<p>My question is: how do I write my <code>main()</code>? More specifically, how do I build that <code>tcx</code>?</p>
<p>(note in the meantime I got that answer):<br>
<span class="user-mention silent" data-user-id="232545">Joshua Nelson</span> <a href="#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/Extract.20callgraph.20of.20a.20crate/near/216012863">said</a>:</p>
<blockquote>
<p>see <a href="https://github.com/rust-lang/rust-clippy/blob/master/src/driver.rs#L418-L422">https://github.com/rust-lang/rust-clippy/blob/master/src/driver.rs#L418-L422</a> for examples of how to use rustc_driver then</p>
</blockquote>



<a name="216012998"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216012998" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216012998">(Nov 08 2020 at 16:09)</a>:</h4>
<p>btw, the way I found that is I know clippy is a reasonably readable codebase, and then I just ran <code>rg interface src/tools/clippy</code></p>



<a name="216013076"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216013076" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216013076">(Nov 08 2020 at 16:10)</a>:</h4>
<p>Thanks</p>



<a name="216013650"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216013650" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216013650">(Nov 08 2020 at 16:25)</a>:</h4>
<p>So, the link just gave is an excellent example of what my main should should like. What I need to do is to change the last 5 lines. More specifically <code>rustc_driver::RunCompiler::new(&amp;args, callbacks).run()</code> by using my own <code>callbacks</code>. However I don't understand how I should register the code doing <code>self.hir().krate().body_ids.iter()</code>. I think it's in the implementation of the <a href="https://github.com/rust-lang/rust-clippy/blob/master/src/driver.rs#L70-L93"><code>config()</code></a> function but I don't understand how it works.</p>



<a name="216013798"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216013798" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216013798">(Nov 08 2020 at 16:28)</a>:</h4>
<p>hmm, clippy does this differently from rustdoc - I think because it only has to override <code>register_lints</code> and nothing else?</p>



<a name="216013808"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216013808" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216013808">(Nov 08 2020 at 16:28)</a>:</h4>
<p>the way rustdoc does this is <a href="https://github.com/rust-lang/rust/blob/master/src/librustdoc/core.rs#L430L432">https://github.com/rust-lang/rust/blob/master/src/librustdoc/core.rs#L430L432</a>, which has access to a full <code>Compiler</code></p>



<a name="216013814"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216013814" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216013814">(Nov 08 2020 at 16:28)</a>:</h4>
<p>and then gets a <code>tcx</code> from <a href="https://github.com/rust-lang/rust/blob/master/src/librustdoc/core.rs#L470">https://github.com/rust-lang/rust/blob/master/src/librustdoc/core.rs#L470</a></p>



<a name="216013840"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216013840" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216013840">(Nov 08 2020 at 16:29)</a>:</h4>
<p>so I think the main thing is to set up a  <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_interface/interface/struct.Config.html"><code>Config</code></a> to pass to <code>create_compiler_and_run</code>.</p>



<a name="216013843"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216013843" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216013843">(Nov 08 2020 at 16:29)</a>:</h4>
<p>(deleted)</p>



<a name="216013985"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216013985" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216013985">(Nov 08 2020 at 16:32)</a>:</h4>
<p>alternatively I think you could hack it by having <code>register_lints</code> do things other than run lints</p>



<a name="216014074"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216014074" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216014074">(Nov 08 2020 at 16:34)</a>:</h4>
<p>This looks like an excellent starting point.</p>



<a name="216014096"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216014096" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216014096">(Nov 08 2020 at 16:34)</a>:</h4>
<p>just ignore the hackery around lints and extern crates <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>



<a name="216014114"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216014114" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216014114">(Nov 08 2020 at 16:35)</a>:</h4>
<p><span class="user-mention silent" data-user-id="232545">Joshua Nelson</span> <a href="#narrow/stream/122652-new-members/topic/Hi.20from.20Robin/near/216010827">said</a>:</p>
<blockquote>
<p>If you use rustup-toolchain-install-master you don't need to build from source</p>
</blockquote>
<p>How do I tell cargo to use the internal of rustc that I installed with <code>rustup-toolchain-install-master</code>? I assume I can't just add stuff in the <code>dependency</code> section of my <code>Cargo.toml</code>.</p>



<a name="216014120"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216014120" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216014120">(Nov 08 2020 at 16:35)</a>:</h4>
<p>I'd see how clippy does it</p>



<a name="216014163"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216014163" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216014163">(Nov 08 2020 at 16:36)</a>:</h4>
<p>I think you just need <code>feature(rustc_private)</code> actually?</p>



<a name="216014166"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216014166" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216014166">(Nov 08 2020 at 16:36)</a>:</h4>
<p>or something like that</p>



<a name="216014174"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216014174" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216014174">(Nov 08 2020 at 16:36)</a>:</h4>
<p>ah! That's simpler than what I thought.</p>



<a name="216014271"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216014271" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216014271">(Nov 08 2020 at 16:39)</a>:</h4>
<p>Thanks for everything. I will try to test this, but I need to take a break right now!</p>



<a name="216015870"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216015870" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lqd <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216015870">(Nov 08 2020 at 17:16)</a>:</h4>
<p>something like <a href="https://github.com/japaric/cargo-call-stack">https://github.com/japaric/cargo-call-stack</a> or like <a href="https://github.com/praezi/rust">https://github.com/praezi/rust</a> ?</p>



<a name="216022471"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216022471" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216022471">(Nov 08 2020 at 19:55)</a>:</h4>
<p>Yes. Last time I tried the former didn't worked for me, and the later (AFAIK) was conceived for a whole crater run and not just the current crate. I also plan to improve the output (like direct link to the documentation, …). But I will re-take a look at both, thanks for reminding me of their existance.</p>



<a name="216183753"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216183753" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216183753">(Nov 10 2020 at 08:43)</a>:</h4>
<p>I really have the feeling that I'm totally loosing my time <span aria-label="sad" class="emoji emoji-2639" role="img" title="sad">:sad:</span> I tried to create a <code>main()</code> for more than two hours still without any success… Given that I think I will need to be able to access the <code>tcx</code>, I thought that the best idea would be to start from <code>rustdoc</code>, and then shave what I don't need. Given that <code>lib.rs</code> in <code>rustdoc</code> has a main, I assume it was going to be a simple change in <code>Cargo.toml</code> (changing it from lib to binary). That's not the case:</p>
<ul>
<li>I get way too much clippy warning</li>
<li>all dependencies (<code>lazy_static</code> and <code>tracing</code>) are not specified in the <code>Cargo.toml</code></li>
<li>apparently having <code>#[feature(rustc_private)]</code> is not enough, cargo complains that he can't find the extern crate <code>rustc_ast</code></li>
</ul>
<p>I don't know how to move forward. I would like to spend time on adding feature, not on the build system. One of the top reason I prefer Rust to C++ <em>is</em> the build system, and frankly, the rust repo is a mess.<br>
/rant</p>
<p>But I still want to move forward.</p>



<a name="216184773"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216184773" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216184773">(Nov 10 2020 at 08:54)</a>:</h4>
<p>To sum-up, how do I create a main, that give me access to <code>tcx</code>.</p>



<a name="216189787"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216189787" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lqd <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216189787">(Nov 10 2020 at 09:48)</a>:</h4>
<p>for a binary, <a href="https://github.com/rust-lang/miri/blob/master/src/bin/miri.rs">miri</a> is another example of an executable giving you access to the tcx</p>



<a name="216194937"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216194937" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216194937">(Nov 10 2020 at 10:48)</a>:</h4>
<p>Solved:</p>
<p><span class="user-mention silent" data-user-id="133247">bjorn3</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/How.20to.20create.20an.20executable.20accessing.20.60rustc_private.60.3F/near/216187308">said</a>:</p>
<blockquote>
<p>You need to install both the <code>rustc-dev</code> and <code>llvm-tools-preview</code> rustup components. The former depends on the later, but rustup doesn't have a way to state such dependency.</p>
</blockquote>



<a name="216237442"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216237442" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216237442">(Nov 10 2020 at 16:36)</a>:</h4>
<p>Given my difficulties on building the application itself, I tried to see how I should display the callgraph. I want to track both direct function call and indirect ones (through function pointers). So far,here is what I got:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">condition</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">false</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="k">if</span><span class="w"> </span><span class="n">condition</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">m1</span>::<span class="n">foo1</span><span class="p">(</span><span class="n">m2</span>::<span class="n">bar</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">m1</span>::<span class="n">foo3</span><span class="p">(</span><span class="n">m2</span>::<span class="n">bar</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">mod</span> <span class="nn">m1</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">foo1</span><span class="o">&lt;</span><span class="n">F</span>: <span class="nb">Fn</span><span class="p">()</span><span class="o">&gt;</span><span class="p">(</span><span class="n">fct</span>: <span class="nc">F</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">foo2</span><span class="p">(</span><span class="n">fct</span><span class="p">)</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">foo2</span><span class="o">&lt;</span><span class="n">F</span>: <span class="nb">Fn</span><span class="p">()</span><span class="o">&gt;</span><span class="p">(</span><span class="n">fct</span>: <span class="nc">F</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">fct</span><span class="p">()</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">foo3</span><span class="o">&lt;</span><span class="n">F</span>: <span class="nb">Fn</span><span class="p">()</span><span class="o">&gt;</span><span class="p">(</span><span class="n">fct</span>: <span class="nc">F</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">foo2</span><span class="p">(</span><span class="n">fct</span><span class="p">)</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">mod</span> <span class="nn">m2</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">bar</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">baz</span><span class="p">();</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>

<span class="w">    </span><span class="k">fn</span> <span class="nf">baz</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">println</span><span class="o">!</span><span class="p">(</span><span class="s">"hello word"</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>I will try to generate this graph: <em>Note: graphviz syntax doesn't seems to be supported</em></p>
<div class="codehilite"><pre><span></span><code>strict digraph {

    subgraph cluster0 {
        label = &lt;&lt;u&gt;test1&lt;/u&gt;&gt;
        fontcolor = green
        color=none
        href=&quot;target/doc/test1/index.html&quot;

        &quot;main&quot; [shape=none; label=&quot;main&quot;; href=&quot;target/doc/test1/index.html&quot;]

        subgraph cluster1·
        {
            label = &lt;&lt;u&gt;m1&lt;/u&gt;&gt;
            fontcolor = green
            color = green
            href=&quot;target/doc/test1/m1/index.html&quot;

            &quot;m1::foo1&quot; [shape=none; label=&quot;foo1&quot;; href=&quot;target/doc/test1/m1/fn.foo1.html&quot;]
            &quot;m1::foo2&quot; [shape=none; label=&quot;foo2&quot;; href=&quot;target/doc/test1/m1/fn.foo2.html&quot;]
            &quot;m1::foo3&quot; [shape=none; label=&quot;foo3&quot;; href=&quot;target/doc/test1/m1/fn.foo3.html&quot;]

            &quot;m1::foo1(arg)&quot;[label=&quot;&quot;; fixedsize=&quot;false&quot;; width=0; height=0; shape=none]
            &quot;m1::foo2(arg)&quot;[label=&quot;&quot;; fixedsize=&quot;false&quot;; width=0; height=0; shape=none]
            &quot;m1::foo3(arg)&quot;[label=&quot;&quot;; fixedsize=&quot;false&quot;; width=0; height=0; shape=none]
        }

        subgraph cluster2·
        {
            label = &lt;&lt;u&gt;m2&lt;/u&gt;&gt;
            fontcolor = green
            color = green
            href=&quot;target/doc/test1/m2/index.html&quot;

            &quot;m2::bar&quot; [shape=none; label=&quot;bar&quot;; href=&quot;target/doc/test1/m2/fn.bar.html&quot;]
            &quot;m2::baz&quot; [shape=none; label=&quot;baz&quot;; href=&quot;target/doc/test1/m2/fn.baz.html&quot;]
        }
    }


    &quot;main&quot; -&gt; &quot;m1::foo1(arg)&quot; [arrowhead=None]; &quot;m1::foo1(arg)&quot; -&gt; &quot;m1::foo1&quot;; &quot;m1::foo1(arg)&quot; -&gt; &quot;m2::bar&quot; [style=dotted; constraint=false]
    &quot;main&quot; -&gt; &quot;m1::foo3(arg)&quot; [arrowhead=None]; &quot;m1::foo3(arg)&quot; -&gt; &quot;m1::foo3&quot;; &quot;m1::foo3(arg)&quot; -&gt; &quot;m2::bar&quot; [style=dotted; constraint=false]
    &quot;m1::foo1&quot; -&gt; &quot;m1::foo2(arg)&quot; [arrowhead=None]; &quot;m1::foo2(arg)&quot; -&gt; &quot;m1::foo2&quot;; &quot;m1::foo2(arg)&quot; -&gt; &quot;m1::foo1(arg)&quot; [style=dotted; constraint=false]
    &quot;m1::foo3&quot; -&gt; &quot;m1::foo2(arg)&quot; [arrowhead=None]; &quot;m1::foo2(arg)&quot; -&gt; &quot;m1::foo2&quot;; &quot;m1::foo2(arg)&quot; -&gt; &quot;m1::foo3(arg)&quot; [style=dotted; constraint=false]
    &quot;m1::foo2&quot; -&gt; &quot;m1::foo2(arg)&quot; [style=dotted; arrowhead=None; constraint=false]
    &quot;m2::bar&quot; -&gt; &quot;m2::baz&quot;

}
</code></pre></div>
<p>Which will produce the following svg:<br>
<a href="/user_uploads/4715/5FX7oIizoEkF_ATEvOKBvRGN/test1.svg">test1.svg</a></p>



<a name="216237734"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216237734" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216237734">(Nov 10 2020 at 16:38)</a>:</h4>
<p>The hard lines are direct call, while dotted lines are the function pointers. Modules are in green. All text elements have a direct link to the associated documentation generated by rustdoc (currently hardcoded to the path in my own computer).</p>



<a name="216261573"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216261573" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216261573">(Nov 10 2020 at 19:27)</a>:</h4>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="w">    </span><span class="k">for</span><span class="w"> </span><span class="n">body</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">tcx</span><span class="p">.</span><span class="n">hir</span><span class="p">().</span><span class="n">krate</span><span class="p">().</span><span class="n">body_ids</span><span class="p">.</span><span class="n">iter</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">dbg</span><span class="o">!</span><span class="p">(</span><span class="n">body</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="k">for</span><span class="w"> </span><span class="n">owner</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">tcx</span><span class="p">.</span><span class="n">body_owners</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">dbg</span><span class="o">!</span><span class="p">(</span><span class="n">owner</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>This code gives me access to respectively the <code>BodyId</code> and the <code>DefId</code> of all the items  of the code I'm analyzing. How do I get the function name, or the node of the called functions? I was expecting to have some kind of function like <code>DefId::name()</code>, or being able to use use id as index of some kind of container, but I can't find how to do it.</p>



<a name="216261611"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216261611" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216261611">(Nov 10 2020 at 19:27)</a>:</h4>
<p><a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyCtxt.html#method.item_name">https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyCtxt.html#method.item_name</a></p>



<a name="216261643"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216261643" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216261643">(Nov 10 2020 at 19:27)</a>:</h4>
<p>almost everything is a method on tcx</p>



<a name="216261710"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216261710" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216261710">(Nov 10 2020 at 19:28)</a>:</h4>
<p>ok, perfect!</p>



<a name="216266031"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216266031" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216266031">(Nov 10 2020 at 20:02)</a>:</h4>
<p>And how do I get from the <code>DefId</code> (I assume it's the identifier of the function) to the tree inside? I'm expecting to be able to do something like</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">for</span><span class="w"> </span><span class="n">body</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">tcx</span><span class="p">.</span><span class="n">body_owners</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">     </span><span class="kd">let</span><span class="w"> </span><span class="n">function_name</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">tcx</span><span class="p">.</span><span class="n">def_path_str</span><span class="p">(</span><span class="n">owner</span><span class="p">.</span><span class="n">to_def_id</span><span class="p">());</span><span class="w"></span>
<span class="w">     </span><span class="k">for</span><span class="w"> </span><span class="n">item</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">tcx</span><span class="p">.</span><span class="n">get_tree_from</span><span class="p">(</span><span class="n">body</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="c1">// I can't write this line</span>
<span class="w">          </span><span class="k">if</span><span class="w"> </span><span class="n">item</span><span class="p">.</span><span class="k">type</span> <span class="o">!=</span><span class="w"> </span><span class="n">callable</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">              </span><span class="k">continue</span><span class="p">;</span><span class="w"></span>
<span class="w">          </span><span class="p">}</span><span class="w"></span>
<span class="w">          </span><span class="n">println</span><span class="o">!</span><span class="p">(</span><span class="s">"{} is called by {}"</span><span class="p">,</span><span class="w"> </span><span class="n">tcx</span><span class="p">.</span><span class="n">def_path_str</span><span class="p">(</span><span class="n">item</span><span class="p">),</span><span class="w"> </span><span class="n">function_name</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="216266683"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216266683" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216266683">(Nov 10 2020 at 20:07)</a>:</h4>
<p>maybe <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyCtxt.html#method.typeck_body">https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyCtxt.html#method.typeck_body</a> ?</p>



<a name="216266724"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216266724" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216266724">(Nov 10 2020 at 20:07)</a>:</h4>
<p>btw the way I'm finding these is ctrl+f 'body' <span aria-label="laughing" class="emoji emoji-1f606" role="img" title="laughing">:laughing:</span></p>



<a name="216267077"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216267077" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216267077">(Nov 10 2020 at 20:10)</a>:</h4>
<p>I did ctrl+f, but I think I didn't realized that <code>typecheck_body</code> was what I wanted. I guess I start to be tired!</p>



<a name="216267179"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216267179" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216267179">(Nov 10 2020 at 20:11)</a>:</h4>
<p>well, I'm not sure either <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>



<a name="216267206"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216267206" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216267206">(Nov 10 2020 at 20:11)</a>:</h4>
<p>maybe look how <code>rustc_typeck</code> does this</p>



<a name="216267451"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216267451" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216267451">(Nov 10 2020 at 20:13)</a>:</h4>
<p>Will do tomorow</p>



<a name="216318350"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216318350" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216318350">(Nov 11 2020 at 08:32)</a>:</h4>
<p>With this, I'm able to access to all functions, get their names, the module they are in, and their bodies:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="kd">let</span><span class="w"> </span><span class="n">hir</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">tcx</span><span class="p">.</span><span class="n">hir</span><span class="p">();</span><span class="w"></span>
<span class="kd">let</span><span class="w"> </span><span class="n">krate</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">hir</span><span class="p">.</span><span class="n">krate</span><span class="p">();</span><span class="w"></span>
<span class="k">for</span><span class="w"> </span><span class="n">body</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">krate</span><span class="p">.</span><span class="n">body_ids</span><span class="p">.</span><span class="n">iter</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">_module</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">dbg</span><span class="o">!</span><span class="p">(</span><span class="n">tcx</span><span class="p">.</span><span class="n">def_path_str</span><span class="p">(</span><span class="n">tcx</span><span class="p">.</span><span class="n">parent_module</span><span class="p">(</span><span class="n">body</span><span class="p">.</span><span class="n">hir_id</span><span class="p">).</span><span class="n">to_def_id</span><span class="p">()));</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">_function_name</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">dbg</span><span class="o">!</span><span class="p">(</span><span class="n">tcx</span><span class="p">.</span><span class="n">def_path_str</span><span class="p">(</span><span class="n">body</span><span class="p">.</span><span class="n">hir_id</span><span class="p">.</span><span class="n">owner</span><span class="p">.</span><span class="n">to_def_id</span><span class="p">()));</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">_body</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">dbg</span><span class="o">!</span><span class="p">(</span><span class="o">&amp;</span><span class="n">krate</span><span class="p">.</span><span class="n">body</span><span class="p">(</span><span class="o">*</span><span class="n">body</span><span class="p">).</span><span class="n">value</span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>Now, I would need to be able to walk on that graph in order to search for all called function. I can totally implement that tree traversal, by inspecting the <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/enum.ExprKind.html">kind</a> recursively, but I was wondering if there was an easier way. Something like:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">walk_graph_depth_first</span><span class="p">(</span><span class="n">hir</span>: <span class="nc">Map</span><span class="o">&lt;'</span><span class="na">tcx</span><span class="o">&gt;</span><span class="p">,</span><span class="w"> </span><span class="n">body</span>: <span class="nc">Body</span><span class="o">&lt;'</span><span class="na">hir</span><span class="o">&gt;</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">Impl</span><span class="w"> </span><span class="nb">Iterator</span><span class="o">&lt;</span><span class="n">Item</span><span class="o">=</span><span class="n">HidId</span><span class="o">&gt;</span><span class="p">;</span><span class="w"> </span><span class="c1">// &lt;- I need this function</span>

<span class="k">for</span><span class="w"> </span><span class="n">hir_id</span><span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="n">walk_graph_depth_first</span><span class="p">(</span><span class="n">hir</span><span class="p">,</span><span class="w"> </span><span class="n">body</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">item</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">hir</span><span class="p">.</span><span class="n">item</span><span class="p">(</span><span class="n">hir_id</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="k">if</span><span class="w"> </span><span class="kd">let</span><span class="w"> </span><span class="nb">Fn</span><span class="p">(</span><span class="n">signature</span><span class="p">,</span><span class="w"> </span><span class="n">generic</span><span class="p">,</span><span class="w"> </span><span class="n">body_id</span><span class="p">)</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">item</span><span class="p">.</span><span class="n">kind</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="c1">// do something with the called function</span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="216322393"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216322393" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216322393">(Nov 11 2020 at 09:19)</a>:</h4>
<p>Would it make sense to operate on MIR instead of HIR? If you use <code>-Zalways-encode-mir</code>, you can access all the MIR of other crates. The MIR also has all overloaded operator calls desugared to regular calls.</p>



<a name="216326904"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216326904" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216326904">(Nov 11 2020 at 10:09)</a>:</h4>
<p>Actually IDK. I would like to be able to get the callgraph of the current crate, but I'm not sure if I need to be able to also get the one of all depending crates. I also would like to be able to track the source of indirect calls, like function pointers. Do you think that MIR is more suited to this analysis?</p>



<a name="216327189"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216327189" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216327189">(Nov 11 2020 at 10:12)</a>:</h4>
<p>The rustc development guide on <a href="https://rustc-dev-guide.rust-lang.org/mir/index.html">MIR</a> seems to back-up your claim <span aria-label="smile" class="emoji emoji-1f642" role="img" title="smile">:smile:</span> (emphasis mine):</p>
<blockquote>
<p>If you'd like a very high-level introduction to MIR, as well as some of the compiler concepts that it relies on (such as <strong>control-flow graphs</strong> and desugaring), you may enjoy the rust-lang blog post that introduced MIR.</p>
</blockquote>



<a name="216327251"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216327251" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216327251">(Nov 11 2020 at 10:13)</a>:</h4>
<p>(posted my previous message in the wrong topic)</p>



<a name="216327304"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216327304" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216327304">(Nov 11 2020 at 10:14)</a>:</h4>
<p>It's what I thought too ^^</p>



<a name="216327517"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216327517" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216327517">(Nov 11 2020 at 10:17)</a>:</h4>
<p>You may want to take a look at the mono item collector: <a href="https://github.com/rust-lang/rust/blob/38030ffb4e735b26260848b744c0910a5641e1db/compiler/rustc_mir/src/monomorphize/collector.rs">https://github.com/rust-lang/rust/blob/38030ffb4e735b26260848b744c0910a5641e1db/compiler/rustc_mir/src/monomorphize/collector.rs</a> You will probably want to adapt it to not monomorphize, consider all functions as roots and not filter functions that would be codegened in other crates.</p>



<a name="216327605"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216327605" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216327605">(Nov 11 2020 at 10:18)</a>:</h4>
<p>Let me see</p>



<a name="216378119"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216378119" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216378119">(Nov 11 2020 at 17:59)</a>:</h4>
<p>Are call to const function still present in MIR? I also don't think that macro are visible anymore. MIR seems effectively way simpler to analyze than HIR, but I have the feeling that too much information have already been lost.</p>



<a name="216378367"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216378367" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216378367">(Nov 11 2020 at 18:01)</a>:</h4>
<p>IIRC const evaluation is ran on MIR, so MIR has to be generated before const evaluation</p>



<a name="216378416"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216378416" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216378416">(Nov 11 2020 at 18:01)</a>:</h4>
<p>Ah, that's good to know :)</p>



<a name="216378525"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216378525" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216378525">(Nov 11 2020 at 18:02)</a>:</h4>
<p>Macros are expanded before though</p>



<a name="216378576"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216378576" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216378576">(Nov 11 2020 at 18:02)</a>:</h4>
<p>I guess that's ok. I have no idea how I should be displaying them anyway.</p>



<a name="216378767"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216378767" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216378767">(Nov 11 2020 at 18:04)</a>:</h4>
<p>This is for the callgraph you're working on? I also think it makes more sense to consider the result of macro expansion rather than the macro</p>



<a name="216378889"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216378889" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216378889">(Nov 11 2020 at 18:05)</a>:</h4>
<p>So, my next question is going to be: how do I construct the MIR? I'm using librustdoc as a base. I was modifying <a href="https://github.com/rust-lang/rust/blob/master/src/librustdoc/core.rs#L490">`run_global_ctxt</a> which gave me access to the HIR, but since now I would need to access to MIR, I'm not sure it's the right place anymore.</p>



<a name="216378907"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216378907" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216378907">(Nov 11 2020 at 18:05)</a>:</h4>
<p>And yes, it's still for the callgraph.</p>



<a name="216379014"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216379014" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216379014">(Nov 11 2020 at 18:06)</a>:</h4>
<p>MIR is constructed in <code>rustc_mir_build</code>, I guess you might want to check entry points there</p>



<a name="216379097"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216379097" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216379097">(Nov 11 2020 at 18:07)</a>:</h4>
<p>That's frustrating, I've discovered quite a lot of the inside of rustc (that's really interesting), but at the same time I have still not wrote a single line that will be really useful for that project!</p>



<a name="216379267"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216379267" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216379267">(Nov 11 2020 at 18:08)</a>:</h4>
<p>I'm also currently trying to understand how MIR is generated for match expressions, and... I now understand why it feels so magical to use <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>



<a name="216379345"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216379345" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> vn-ki <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216379345">(Nov 11 2020 at 18:09)</a>:</h4>
<p>The covers of compiler theory textbooks have a wizard for a reason <span aria-label="laughing" class="emoji emoji-1f606" role="img" title="laughing">:laughing:</span></p>



<a name="216379455"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216379455" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216379455">(Nov 11 2020 at 18:10)</a>:</h4>
<p><span class="user-mention" data-user-id="255061">@LeSeulArtichaut</span> Did you read the introduction <a href="https://blog.rust-lang.org/2016/04/19/MIR.html">blog post</a> to MIR? Match lowering is explained in it.</p>



<a name="216379494"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216379494" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216379494">(Nov 11 2020 at 18:10)</a>:</h4>
<p>Yes, but it's unfortunately just an overview <span aria-label="eyes" class="emoji emoji-1f440" role="img" title="eyes">:eyes:</span></p>



<a name="216379515"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216379515" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216379515">(Nov 11 2020 at 18:11)</a>:</h4>
<p>ah!</p>



<a name="216379800"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216379800" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216379800">(Nov 11 2020 at 18:13)</a>:</h4>
<p>is rustdoc building MIR at one point?</p>



<a name="216379861"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216379861" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216379861">(Nov 11 2020 at 18:14)</a>:</h4>
<p>no, rustdoc specifically avoids building mir</p>



<a name="216379887"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216379887" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216379887">(Nov 11 2020 at 18:14)</a>:</h4>
<p>ah, so starting from rustdoc isn't a good idea then!</p>



<a name="216379899"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216379899" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216379899">(Nov 11 2020 at 18:14)</a>:</h4>
<p>I think it's just <code>tcx.analysis()</code> though</p>



<a name="216379932"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216379932" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216379932">(Nov 11 2020 at 18:15)</a>:</h4>
<p><a href="https://github.com/rust-lang/rust/pull/73566">https://github.com/rust-lang/rust/pull/73566</a> has way more info about this than you want</p>



<a name="216380018"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216380018" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216380018">(Nov 11 2020 at 18:15)</a>:</h4>
<p>specifically the changes to <a href="https://github.com/rust-lang/rust/pull/73566/files#diff-2af9d5298f727457226da68b0dc427149fc68b3aa0d0fe64cca15b63c34af997"><code>librustdoc/core.rs</code></a></p>



<a name="216383859"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216383859" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216383859">(Nov 11 2020 at 18:49)</a>:</h4>
<p>I'm not sure I understand everything. What you said was that rustdoc intentionally avoids buildir MIR, because otherwise part of its analysis is invalidated, and results in ICE. Then you showed me a commit in which there is an implementation of the <code>Visitor</code> trait, which is the way I should walk the graph, if I want to be able to do the analysis on the HIR. Did I get it right?</p>



<a name="216383907"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216383907" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216383907">(Nov 11 2020 at 18:49)</a>:</h4>
<p>right, yes, the deleted code is what is checking MIR</p>



<a name="216383963"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216383963" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216383963">(Nov 11 2020 at 18:50)</a>:</h4>
<p><a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyCtxt.html#method.analysis">https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyCtxt.html#method.analysis</a></p>



<a name="216384018"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216384018" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216384018">(Nov 11 2020 at 18:50)</a>:</h4>
<p>hmm it doesn't actually give you back anything useful though <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/query/queries/struct.analysis.html#impl-QueryConfig">https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/query/queries/struct.analysis.html#impl-QueryConfig</a></p>



<a name="216384068"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216384068" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216384068">(Nov 11 2020 at 18:51)</a>:</h4>
<p>It's not really obvious that <code>&lt;analysis&lt;'tcx&gt; as QueryConfig&gt;::Stored</code> means <code>MIR</code> <span aria-label="face with thermometer" class="emoji emoji-1f912" role="img" title="face with thermometer">:face_with_thermometer:</span></p>



<a name="216384102"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216384102" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216384102">(Nov 11 2020 at 18:51)</a>:</h4>
<p>yeah I'm working on that too <a href="https://github.com/rust-lang/rust/pull/77467">https://github.com/rust-lang/rust/pull/77467</a></p>



<a name="216384117"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216384117" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216384117">(Nov 11 2020 at 18:51)</a>:</h4>
<p>don't get me started</p>



<a name="216384380"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216384380" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216384380">(Nov 11 2020 at 18:53)</a>:</h4>
<p>Oh, that's good!</p>



<a name="216384490"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216384490" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216384490">(Nov 11 2020 at 18:54)</a>:</h4>
<p>it's blocked for ages on <a href="https://github.com/rust-lang/rust/pull/78082">https://github.com/rust-lang/rust/pull/78082</a> unfortunately</p>



<a name="216385355"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216385355" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216385355">(Nov 11 2020 at 19:01)</a>:</h4>
<p>To sum-up. What I need to do to be able to extract the call-graph is:</p>
<ol>
<li>get the list of functions with <code>tcx.hir().krate().body_ids.iter()</code> (the name is <code>tcx.def_path_str(body.hir_id.owner.to_def_id())</code></li>
<li>create a type <code>SearchFunctionCall</code> that impl <code>Visitor&lt;'tcx&gt;</code>, and that export the name of all function call encountered</li>
<li>call <code>SearchFunctionCall::new().visit_body(body)</code> with <code>body</code> being the object I got in step 1.</li>
</ol>
<p>Am I right?</p>



<a name="216385411"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216385411" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216385411">(Nov 11 2020 at 19:01)</a>:</h4>
<p>that's the way to do it in HIR, I think</p>



<a name="216385446"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216385446" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216385446">(Nov 11 2020 at 19:01)</a>:</h4>
<p>I'm not sure how <code>SearchFunctionCall</code> would work</p>



<a name="216386278"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216386278" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216386278">(Nov 11 2020 at 19:08)</a>:</h4>
<p>Given what I did with my experiment with graphviz, I need to collect:</p>
<ul>
<li>For each module the name of the function declared in them</li>
<li>For each function the name of the function they are calling</li>
</ul>
<p>Both of those step are independent, and can be done in parallel. What I am going to do is to create a list (a <code>Vec</code> to be more precise) of the id of the function that are called. That <code>Vec</code> will be a field of the <code>SearchFunctionCall</code>.</p>



<a name="216388626"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216388626" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216388626">(Nov 11 2020 at 19:32)</a>:</h4>
<p>By the way, should I create a standalone tool, or something that integrates into rustdoc?</p>



<a name="216388880"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216388880" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216388880">(Nov 11 2020 at 19:34)</a>:</h4>
<p><span class="user-mention silent" data-user-id="255061">LeSeulArtichaut</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/Extract.20callgraph.20of.20a.20crate/near/216379267">said</a>:</p>
<blockquote>
<p>I'm also currently trying to understand how MIR is generated for match expressions, and... I now understand why it feels so magical to use <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>
</blockquote>
<p>It's somehow both comforting and scary to open that file and see the huge comment with a paper reference at the top explaining how it works <span aria-label="grimacing" class="emoji emoji-1f62c" role="img" title="grimacing">:grimacing:</span></p>



<a name="216389118"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216389118" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216389118">(Nov 11 2020 at 19:36)</a>:</h4>
<p>I would say that it's the kind of thing that are not <em>that</em> hard to understand, but extremely hard to explain using only top-to bottom text (ie, no diagram, flow chart, …).</p>



<a name="216389265"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216389265" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216389265">(Nov 11 2020 at 19:37)</a>:</h4>
<p>I don't like graphs. Since indexes are only checked at runtime, the compiler can't help me. That's a very weird feeling when working in Rust. I feel naked without the compiler!</p>



<a name="216389357"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216389357" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216389357">(Nov 11 2020 at 19:38)</a>:</h4>
<p>there's a short section in <a href="https://rustc-dev-guide.rust-lang.org/pat-exhaustive-checking.html?highlight=match#pattern-and-exhaustiveness-checking">https://rustc-dev-guide.rust-lang.org/pat-exhaustive-checking.html?highlight=match#pattern-and-exhaustiveness-checking</a></p>



<a name="216390056"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216390056" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216390056">(Nov 11 2020 at 19:44)</a>:</h4>
<p>Why does <code>hir.local_def_id(id);</code> fails?</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="n">error</span>: <span class="nc">internal</span><span class="w"> </span><span class="n">compiler</span><span class="w"> </span><span class="n">error</span>: <span class="o">/</span><span class="n">home</span><span class="o">/</span><span class="n">robin</span><span class="o">/</span><span class="p">.</span><span class="n">rustup</span><span class="o">/</span><span class="n">toolchains</span><span class="o">/</span><span class="n">nightly</span><span class="o">-</span><span class="n">x86_64</span><span class="o">-</span><span class="n">unknown</span><span class="o">-</span><span class="n">linux</span><span class="o">-</span><span class="n">gnu</span><span class="o">/</span><span class="n">lib</span><span class="o">/</span><span class="n">rustlib</span><span class="o">/</span><span class="n">src</span><span class="o">/</span><span class="n">rust</span><span class="o">/</span><span class="n">compiler</span><span class="o">/</span><span class="n">rustc_middle</span><span class="o">/</span><span class="n">src</span><span class="o">/</span><span class="n">hir</span><span class="o">/</span><span class="n">map</span><span class="o">/</span><span class="k">mod</span><span class="p">.</span><span class="n">rs</span>:<span class="mi">163</span>:<span class="mi">13</span>: <span class="nc">local_def_id</span>: <span class="nc">no</span><span class="w"> </span><span class="n">entry</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="err">`</span><span class="n">HirId</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">owner</span>: <span class="nc">DefId</span><span class="p">(</span><span class="mi">0</span>:<span class="mi">3</span><span class="w"> </span><span class="o">~</span><span class="w"> </span><span class="n">main</span><span class="p">[</span><span class="mi">8787</span><span class="p">]</span>::<span class="n">main</span><span class="p">),</span><span class="w"> </span><span class="n">local_id</span>: <span class="mi">6</span><span class="w"> </span><span class="p">}</span><span class="err">`</span><span class="p">,</span><span class="w"> </span><span class="n">which</span><span class="w"> </span><span class="n">has</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="n">map</span><span class="w"> </span><span class="n">of</span><span class="w"> </span><span class="err">`</span><span class="nb">Some</span><span class="p">(</span><span class="n">Entry</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">parent</span>: <span class="nc">HirId</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">owner</span>: <span class="nc">DefId</span><span class="p">(</span><span class="mi">0</span>:<span class="mi">3</span><span class="w"> </span><span class="o">~</span><span class="w"> </span><span class="n">main</span><span class="p">[</span><span class="mi">8787</span><span class="p">]</span>::<span class="n">main</span><span class="p">),</span><span class="w"> </span><span class="n">local_id</span>: <span class="mi">10</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">node</span>: <span class="nc">Expr</span><span class="p">(</span><span class="n">Expr</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">hir_id</span>: <span class="nc">HirId</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">owner</span>: <span class="nc">DefId</span><span class="p">(</span><span class="mi">0</span>:<span class="mi">3</span><span class="w"> </span><span class="o">~</span><span class="w"> </span><span class="n">main</span><span class="p">[</span><span class="mi">8787</span><span class="p">]</span>::<span class="n">main</span><span class="p">),</span><span class="w"> </span><span class="n">local_id</span>: <span class="mi">6</span><span class="w"> </span><span class="p">},</span><span class="w"> </span><span class="n">kind</span>: <span class="nc">Path</span><span class="p">(</span><span class="n">Resolved</span><span class="p">(</span><span class="nb">None</span><span class="p">,</span><span class="w"> </span><span class="n">Path</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">span</span>: <span class="nc">test</span><span class="o">/</span><span class="n">test1</span><span class="o">/</span><span class="n">src</span><span class="o">/</span><span class="n">main</span><span class="p">.</span><span class="n">rs</span>:<span class="mi">35</span>:<span class="mi">5</span>: <span class="mi">35</span>:<span class="mi">8</span><span class="w"> </span><span class="p">(</span><span class="err">#</span><span class="mi">0</span><span class="p">),</span><span class="w"> </span><span class="n">res</span>: <span class="nc">Def</span><span class="p">(</span><span class="nb">Fn</span><span class="p">,</span><span class="w"> </span><span class="n">DefId</span><span class="p">(</span><span class="mi">0</span>:<span class="mi">4</span><span class="w"> </span><span class="o">~</span><span class="w"> </span><span class="n">main</span><span class="p">[</span><span class="mi">8787</span><span class="p">]</span>::<span class="n">foo</span><span class="p">)),</span><span class="w"> </span><span class="n">segments</span>: <span class="p">[</span><span class="n">PathSegment</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">ident</span>: <span class="nc">foo</span><span class="err">#</span><span class="mi">0</span><span class="p">,</span><span class="w"> </span><span class="n">hir_id</span>: <span class="nc">Some</span><span class="p">(</span><span class="n">HirId</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">owner</span>: <span class="nc">DefId</span><span class="p">(</span><span class="mi">0</span>:<span class="mi">3</span><span class="w"> </span><span class="o">~</span><span class="w"> </span><span class="n">main</span><span class="p">[</span><span class="mi">8787</span><span class="p">]</span>::<span class="n">main</span><span class="p">),</span><span class="w"> </span><span class="n">local_id</span>: <span class="mi">5</span><span class="w"> </span><span class="p">}),</span><span class="w"> </span><span class="n">res</span>: <span class="nc">Some</span><span class="p">(</span><span class="nb">Err</span><span class="p">),</span><span class="w"> </span><span class="n">args</span>: <span class="nc">None</span><span class="p">,</span><span class="w"> </span><span class="n">infer_args</span>: <span class="nc">true</span><span class="w"> </span><span class="p">}]</span><span class="w"> </span><span class="p">})),</span><span class="w"> </span><span class="n">attrs</span>: <span class="nc">ThinVec</span><span class="p">(</span><span class="nb">None</span><span class="p">),</span><span class="w"> </span><span class="n">span</span>: <span class="nc">test</span><span class="o">/</span><span class="n">test1</span><span class="o">/</span><span class="n">src</span><span class="o">/</span><span class="n">main</span><span class="p">.</span><span class="n">rs</span>:<span class="mi">35</span>:<span class="mi">5</span>: <span class="mi">35</span>:<span class="mi">8</span><span class="w"> </span><span class="p">(</span><span class="err">#</span><span class="mi">0</span><span class="p">)</span><span class="w"> </span><span class="p">})</span><span class="w"> </span><span class="p">})</span><span class="err">`</span><span class="w"></span>
</code></pre></div>



<a name="216390237"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216390237" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216390237">(Nov 11 2020 at 19:46)</a>:</h4>
<p>expressions don't have a defid</p>



<a name="216390243"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216390243" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216390243">(Nov 11 2020 at 19:46)</a>:</h4>
<p>they're not serialized cross-crate</p>



<a name="216390546"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216390546" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216390546">(Nov 11 2020 at 19:49)</a>:</h4>
<p>ah</p>



<a name="216390598"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216390598" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216390598">(Nov 11 2020 at 19:49)</a>:</h4>
<p>Then why <code>pub fn def_kind(&amp;self, local_def_id: LocalDefId) -&gt; DefKind</code> takes a <code>LocalDefId</code></p>



<a name="216390829"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216390829" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216390829">(Nov 11 2020 at 19:51)</a>:</h4>
<p>anything prefixed with <code>Def</code> is for working with metadata serialized cross crate</p>



<a name="216390855"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216390855" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216390855">(Nov 11 2020 at 19:51)</a>:</h4>
<p>you probably want <code>tcx.hir().get(hir_id)</code> and then match on the <code>Node</code></p>



<a name="216391558"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216391558" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216391558">(Nov 11 2020 at 19:57)</a>:</h4>
<p><span class="user-mention silent" data-user-id="232545">Joshua Nelson</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/Extract.20callgraph.20of.20a.20crate/near/216384102">said</a>:</p>
<blockquote>
<p>yeah I'm working on that too <a href="https://github.com/rust-lang/rust/pull/77467">https://github.com/rust-lang/rust/pull/77467</a></p>
</blockquote>
<p>Oh, that's awesome!</p>



<a name="216391648"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216391648" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216391648">(Nov 11 2020 at 19:58)</a>:</h4>
<p><span class="user-mention" data-user-id="281841">@Robin Moussu</span> What information are you trying to get, and what do you have at your disposal?</p>



<a name="216392127"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216392127" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216392127">(Nov 11 2020 at 20:02)</a>:</h4>
<p>I'm trying to get the type of the node that I'm visiting (I'm visiting recursively all nodes inside a function), and I want to find the function call. I have access to the <code>tcx</code> (so the <code>hir</code>), and the <code>HirId</code> + <code>Path</code> of the node I'm visiting</p>



<a name="216392180"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216392180" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216392180">(Nov 11 2020 at 20:02)</a>:</h4>
<p>I think that <code>tcx.hir().get()</code> is the right track</p>



<a name="216392201"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216392201" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216392201">(Nov 11 2020 at 20:02)</a>:</h4>
<p>you can probably pretty much look at save analysis here</p>



<a name="216392238"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216392238" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216392238">(Nov 11 2020 at 20:03)</a>:</h4>
<p>what is safe analysis?</p>



<a name="216392302"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216392302" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216392302">(Nov 11 2020 at 20:03)</a>:</h4>
<p>it's used by RLS for type info and stuff</p>



<a name="216392330"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216392330" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216392330">(Nov 11 2020 at 20:04)</a>:</h4>
<p>and already implements a way to get the type for a given hir id afaik</p>



<a name="216392380"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216392380" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216392380">(Nov 11 2020 at 20:04)</a>:</h4>
<p>it's part of the rust repo</p>



<a name="216392536"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216392536" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216392536">(Nov 11 2020 at 20:05)</a>:</h4>
<p>Otherwise I'd have suggested maybe <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/intravisit/index.html"><code>rustc_hir::intravisit</code></a></p>



<a name="216392740"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216392740" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216392740">(Nov 11 2020 at 20:06)</a>:</h4>
<p>Which I think would allow you to just define a <code>visit_expr</code> hook, where you can check if the expr is a function call</p>



<a name="216392762"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216392762" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216392762">(Nov 11 2020 at 20:07)</a>:</h4>
<p>And the visitor can handle HIR traversal for you</p>



<a name="216392810"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216392810" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216392810">(Nov 11 2020 at 20:07)</a>:</h4>
<p>That's probably better that what I was trying</p>



<a name="216392864"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216392864" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216392864">(Nov 11 2020 at 20:08)</a>:</h4>
<p>So one issue is that you have to keep the correct typeck_result around if you want to do this on this hir</p>



<a name="216392929"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216392929" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216392929">(Nov 11 2020 at 20:08)</a>:</h4>
<p>save_analysis implements this for the <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_save_analysis/dump_visitor/struct.DumpVisitor.html">https://doc.rust-lang.org/nightly/nightly-rustc/rustc_save_analysis/dump_visitor/struct.DumpVisitor.html</a></p>



<a name="216393059"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216393059" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216393059">(Nov 11 2020 at 20:09)</a>:</h4>
<p>pretty much look at the places where <code>nest_typeck_results</code> is used, the rest can hopefully be ignored</p>



<a name="216393338"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216393338" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216393338">(Nov 11 2020 at 20:12)</a>:</h4>
<p>sry if i missed something, but was there something stopping you from operating on mir?</p>



<a name="216393376"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216393376" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216393376">(Nov 11 2020 at 20:12)</a>:</h4>
<p>that would be a lot easier afaik as you already have the correct types everywhere</p>



<a name="216393456"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216393456" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216393456">(Nov 11 2020 at 20:13)</a>:</h4>
<p>I think types can be ignored if the only goal is to construct a callgraph? Or am I missing something too?</p>



<a name="216393567"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216393567" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216393567">(Nov 11 2020 at 20:14)</a>:</h4>
<p>well you need the type of the called function</p>



<a name="216393596"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216393596" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216393596">(Nov 11 2020 at 20:14)</a>:</h4>
<p>to know which function you are calling</p>



<a name="216393601"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216393601" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216393601">(Nov 11 2020 at 20:14)</a>:</h4>
<p>If I want to be able to report the places where things like functions pointers are set, I need to be able to track the type of variables</p>



<a name="216393613"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216393613" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216393613">(Nov 11 2020 at 20:14)</a>:</h4>
<p>Ah, right, of course <span aria-label="face palm" class="emoji emoji-1f926" role="img" title="face palm">:face_palm:</span></p>



<a name="216393785"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216393785" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216393785">(Nov 11 2020 at 20:16)</a>:</h4>
<p>So the reason I was doing the analysis on the HIR was because <span class="user-mention" data-user-id="232545">@Joshua Nelson</span> helped me to get started, by forking <code>rustdoc</code>, and since <code>rustdoc</code> doesn't generates MIR, I was stuck on HIR</p>



<a name="216393800"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216393800" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216393800">(Nov 11 2020 at 20:16)</a>:</h4>
<p>You could still visit MIR with a <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/visit/trait.Visitor.html"><code>rustc_middle::mir::visit::Visitor</code></a> though</p>



<a name="216393831"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216393831" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216393831">(Nov 11 2020 at 20:16)</a>:</h4>
<p>I'm not against using MIR, I just need a main functions that gives me that MIR <span aria-label="smile" class="emoji emoji-1f642" role="img" title="smile">:smile:</span></p>



<a name="216393913"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216393913" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216393913">(Nov 11 2020 at 20:17)</a>:</h4>
<p>Have you looked at the rustc dev guide, and maybe also the rustc driver?</p>



<a name="216393949"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216393949" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216393949">(Nov 11 2020 at 20:18)</a>:</h4>
<p>(Maybe I shouldn't try to help, I may make things even more confusing)</p>



<a name="216394021"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216394021" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216394021">(Nov 11 2020 at 20:18)</a>:</h4>
<p>In the guide:</p>
<blockquote>
<p>The lowering is triggered by calling the <code>mir_built</code> query.</p>
</blockquote>



<a name="216394085"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216394085" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216394085">(Nov 11 2020 at 20:19)</a>:</h4>
<p>Yes, no, probably, I don't know!<br>
More seriously, I read the part on HIR and MIR from the rustc dev guide, but not the rustc driver</p>



<a name="216395400"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216395400" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216395400">(Nov 11 2020 at 20:32)</a>:</h4>
<p>If I want to create my analysis, what tool can I fork, and where should I put my code? Writing a <code>main()</code> that compiles code up to mir is not something I am able to write on my own with my current understanding of the rust repository.</p>



<a name="216397478"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216397478" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216397478">(Nov 11 2020 at 20:52)</a>:</h4>
<p><a href="https://rustc-dev-guide.rust-lang.org/rustc-driver.html">This chapter</a> is interesting, though a bit short</p>



<a name="216398529"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216398529" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216398529">(Nov 11 2020 at 21:01)</a>:</h4>
<p><span class="user-mention silent" data-user-id="281841">Robin Moussu</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/Extract.20callgraph.20of.20a.20crate/near/216395400">said</a>:</p>
<blockquote>
<p>If I want to create my analysis, what tool can I fork, and where should I put my code? Writing a <code>main()</code> that compiles code up to mir is not something I am able to write on my own with my current understanding of the rust repository.</p>
</blockquote>
<p>Maybe <a href="https://github.com/rust-lang/miri"><code>miri</code></a>?</p>



<a name="216399451"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216399451" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216399451">(Nov 11 2020 at 21:11)</a>:</h4>
<p>What <code>miri</code> does is that it implements <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_driver/trait.Callbacks.html"><code>rustc_driver::Callbacks</code></a></p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">impl</span><span class="w"> </span><span class="n">rustc_driver</span>::<span class="n">Callbacks</span><span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="n">MiriCompilerCalls</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">after_analysis</span><span class="o">&lt;'</span><span class="na">tcx</span><span class="o">&gt;</span><span class="p">(</span><span class="w"></span>
<span class="w">        </span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="bp">self</span><span class="p">,</span><span class="w"></span>
<span class="w">        </span><span class="n">compiler</span>: <span class="kp">&amp;</span><span class="nc">rustc_interface</span>::<span class="n">interface</span>::<span class="n">Compiler</span><span class="p">,</span><span class="w"></span>
<span class="w">        </span><span class="n">queries</span>: <span class="kp">&amp;</span><span class="o">'</span><span class="na">tcx</span> <span class="nc">rustc_interface</span>::<span class="n">Queries</span><span class="o">&lt;'</span><span class="na">tcx</span><span class="o">&gt;</span><span class="p">,</span><span class="w"></span>
<span class="w">    </span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">Compilation</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="c1">// snip</span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>And then it just uses</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="n">run_compiler</span><span class="p">(</span><span class="n">rustc_args</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;</span><span class="k">mut</span><span class="w"> </span><span class="n">MiriCompilerCalls</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">miri_config</span><span class="w"> </span><span class="p">})</span><span class="w"></span>
</code></pre></div>



<a name="216400718"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216400718" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216400718">(Nov 11 2020 at 21:24)</a>:</h4>
<p>And basically once you have the <code>TyCtxt</code> you can do <em>everything</em></p>



<a name="216401033"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216401033" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216401033">(Nov 11 2020 at 21:27)</a>:</h4>
<p>You can use <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyCtxt.html#method.body_owners"><code>TyCtxt::body_owners</code></a> to get an iterator of <code>LocalDefId</code> in the crate, from those <code>LocalDefId</code> you can generate MIR with <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyCtxt.html#method.mir_built"><code>TyCtxt::mir_built</code></a> (or maybe some other <code>mir_something</code> method), to get MIR <code>Body</code>s, and then you can visit those bodies with a MIR <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/visit/trait.Visitor.html"><code>Visitor</code></a></p>



<a name="216401039"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216401039" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216401039">(Nov 11 2020 at 21:27)</a>:</h4>
<p>That would be my intuition</p>



<a name="216401175"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216401175" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216401175">(Nov 11 2020 at 21:29)</a>:</h4>
<p>But perhaps using save analysis is just much better, I don't know what it contains</p>



<a name="216401281"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216401281" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216401281">(Nov 11 2020 at 21:30)</a>:</h4>
<p><span class="user-mention" data-user-id="216206">@lcnr</span> is <a href="https://docs.rs/rls-data/0.19.0/rls_data/struct.Analysis.html"><code>rls_data::Analysis</code></a> the result of save analysis?</p>



<a name="216401313"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216401313" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216401313">(Nov 11 2020 at 21:30)</a>:</h4>
<p>i don't know tbh</p>



<a name="216401358"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216401358" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216401358">(Nov 11 2020 at 21:31)</a>:</h4>
<p>save analysis isn't super well maintained from what I've heard</p>



<a name="216401367"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216401367" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216401367">(Nov 11 2020 at 21:31)</a>:</h4>
<p>i only interacted with the dump_visitor directly while changing some hir owners</p>



<a name="216401383"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216401383" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216401383">(Nov 11 2020 at 21:31)</a>:</h4>
<p><a href="#narrow/stream/131828-t-compiler/topic/Future.20of.20save-analysis">https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Future.20of.20save-analysis</a></p>



<a name="216402081"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216402081" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216402081">(Nov 11 2020 at 21:38)</a>:</h4>
<p>As I understand it I'd find it unlikely that the save analysis contains the bodies of the functions</p>



<a name="216434561"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216434561" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216434561">(Nov 12 2020 at 07:15)</a>:</h4>
<p>Is there some kind of equivalent doc for <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/visit/trait.Visitor.html"><code>rustc_middle::Visitor</code></a> than for <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/itemlikevisit/trait.ItemLikeVisitor.html"><code>hir::Visitor</code></a>? I don't understand what I need to do to be able to create a visitor on MIR.</p>



<a name="216437826"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216437826" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216437826">(Nov 12 2020 at 08:09)</a>:</h4>
<p>I think I managed to get something working, yeah!</p>



<a name="216442658"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216442658" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216442658">(Nov 12 2020 at 09:01)</a>:</h4>
<p>Did you get the visitor working?</p>



<a name="216442775"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216442775" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216442775">(Nov 12 2020 at 09:02)</a>:</h4>
<p>Yes! I just need to format the output, and I should get my graphviz file!</p>



<a name="216443328"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216443328" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216443328">(Nov 12 2020 at 09:09)</a>:</h4>
<p><a href="/user_uploads/4715/6EZTKQRQN9ioi6fpVo9-8Hxv/example.svg">example.svg</a>  generated from </p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">condition</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">false</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="k">if</span><span class="w"> </span><span class="n">condition</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">m1</span>::<span class="n">foo1</span><span class="p">(</span><span class="n">m2</span>::<span class="n">bar</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">m1</span>::<span class="n">foo3</span><span class="p">(</span><span class="n">m2</span>::<span class="n">bar</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">mod</span> <span class="nn">m1</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">foo1</span><span class="o">&lt;</span><span class="n">F</span>: <span class="nb">Fn</span><span class="p">()</span><span class="o">&gt;</span><span class="p">(</span><span class="n">fct</span>: <span class="nc">F</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">foo2</span><span class="p">(</span><span class="n">fct</span><span class="p">)</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">foo2</span><span class="o">&lt;</span><span class="n">F</span>: <span class="nb">Fn</span><span class="p">()</span><span class="o">&gt;</span><span class="p">(</span><span class="n">fct</span>: <span class="nc">F</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">fct</span><span class="p">()</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">foo3</span><span class="o">&lt;</span><span class="n">F</span>: <span class="nb">Fn</span><span class="p">()</span><span class="o">&gt;</span><span class="p">(</span><span class="n">fct</span>: <span class="nc">F</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">foo2</span><span class="p">(</span><span class="n">fct</span><span class="p">)</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">mod</span> <span class="nn">m2</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">bar</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">baz</span><span class="p">();</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>

<span class="w">    </span><span class="k">fn</span> <span class="nf">baz</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">println</span><span class="o">!</span><span class="p">(</span><span class="s">"hello word"</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="216443483"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216443483" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216443483">(Nov 12 2020 at 09:11)</a>:</h4>
<p>It's working perfectly for direct call, the call using function pointers still need some love!</p>



<a name="216445225"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216445225" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216445225">(Nov 12 2020 at 09:30)</a>:</h4>
<p>btw, do you know how to go from a <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/terminator/struct.Terminator.html"><code>Terminator</code></a> whose kind is <code>Func</code> to the function identifier?</p>



<a name="216505917"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216505917" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216505917">(Nov 12 2020 at 18:09)</a>:</h4>
<p>Maybe <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/struct.Constant.html#method.check_static_ptr"><code>Constant::check_static_ptr</code></a>?</p>



<a name="216506190"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216506190" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216506190">(Nov 12 2020 at 18:12)</a>:</h4>
<p>Which you can have via <code>Operand::Constant</code></p>



<a name="216507250"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216507250" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216507250">(Nov 12 2020 at 18:19)</a>:</h4>
<p>No, the value returned by <code>check_static_ptr</code> is <code>None</code> <span aria-label="sad" class="emoji emoji-2639" role="img" title="sad">:sad:</span></p>



<a name="216507716"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216507716" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216507716">(Nov 12 2020 at 18:23)</a>:</h4>
<p>Ideally, I would like to have the same output than what I get with HIR: <code>tcx.def_path_str(my_function.to_def_id())</code>, but I didn't found a way to get a <code>DefID</code> from my <code>Terminator</code> yet.</p>



<a name="216507851"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216507851" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216507851">(Nov 12 2020 at 18:24)</a>:</h4>
<p><span class="user-mention silent" data-user-id="281841">Robin Moussu</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/Extract.20callgraph.20of.20a.20crate/near/216507250">said</a>:</p>
<blockquote>
<p>No, the value returned by <code>check_static_ptr</code> is <code>None</code> <span aria-label="sad" class="emoji emoji-2639" role="img" title="sad">:sad:</span></p>
</blockquote>
<p>In which case?</p>



<a name="216507897"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216507897" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216507897">(Nov 12 2020 at 18:24)</a>:</h4>
<p>At least the one I want!</p>



<a name="216507960"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216507960" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216507960">(Nov 12 2020 at 18:24)</a>:</h4>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="w">  </span><span class="mi">3</span><span class="w"> </span><span class="o">||</span><span class="w"> </span><span class="p">[</span><span class="n">core</span><span class="p">.</span><span class="n">rs</span>:<span class="mi">533</span><span class="p">]</span><span class="w"> </span><span class="o">&amp;</span><span class="n">subfunction</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">m1</span>::<span class="n">foo3</span>::<span class="o">&lt;</span><span class="k">fn</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="n">m2</span>::<span class="n">bar</span><span class="p">}</span><span class="o">&gt;</span><span class="w"></span>
<span class="w">  </span><span class="mi">4</span><span class="w"> </span><span class="o">||</span><span class="w"> </span><span class="p">[</span><span class="n">core</span><span class="p">.</span><span class="n">rs</span>:<span class="mi">534</span><span class="p">]</span><span class="w"> </span><span class="o">&amp;</span><span class="n">subfunction</span><span class="p">.</span><span class="n">constant</span><span class="p">()</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">Some</span><span class="p">(</span><span class="w"></span>
<span class="w">  </span><span class="mi">5</span><span class="w"> </span><span class="o">||</span><span class="w">     </span><span class="n">m1</span>::<span class="n">foo3</span>::<span class="o">&lt;</span><span class="k">fn</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="n">m2</span>::<span class="n">bar</span><span class="p">}</span><span class="o">&gt;</span><span class="p">,</span><span class="w"></span>
<span class="w">  </span><span class="mi">6</span><span class="w"> </span><span class="o">||</span><span class="w"> </span><span class="p">)</span><span class="w"></span>
<span class="w">  </span><span class="mi">7</span><span class="w"> </span><span class="o">||</span><span class="w"> </span><span class="p">[</span><span class="n">core</span><span class="p">.</span><span class="n">rs</span>:<span class="mi">535</span><span class="p">]</span><span class="w"> </span><span class="n">subfunction</span><span class="p">.</span><span class="n">constant</span><span class="p">().</span><span class="n">unwrap</span><span class="p">().</span><span class="n">check_static_ptr</span><span class="p">(</span><span class="n">tcx</span><span class="p">)</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">None</span><span class="w"></span>
</code></pre></div>



<a name="216508027"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216508027" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216508027">(Nov 12 2020 at 18:25)</a>:</h4>
<p>Which is the output of</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="mi">533</span><span class="w">                 </span><span class="n">dbg</span><span class="o">!</span><span class="p">(</span><span class="o">&amp;</span><span class="n">subfunction</span><span class="p">);</span><span class="w"></span>
<span class="mi">534</span><span class="w">                 </span><span class="n">dbg</span><span class="o">!</span><span class="p">(</span><span class="o">&amp;</span><span class="n">subfunction</span><span class="p">.</span><span class="n">constant</span><span class="p">());</span><span class="w"></span>
<span class="mi">535</span><span class="w">                 </span><span class="n">dbg</span><span class="o">!</span><span class="p">(</span><span class="n">subfunction</span><span class="p">.</span><span class="n">constant</span><span class="p">().</span><span class="n">unwrap</span><span class="p">().</span><span class="n">check_static_ptr</span><span class="p">(</span><span class="n">tcx</span><span class="p">));</span><span class="w"></span>
</code></pre></div>



<a name="216508426"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216508426" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216508426">(Nov 12 2020 at 18:28)</a>:</h4>
<p>This was generated with this expression</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="n">module</span><span class="w"> </span><span class="n">m1</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">foo2</span><span class="p">();</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">foo3</span><span class="o">&lt;</span><span class="n">Fct</span>: <span class="nb">Fn</span><span class="p">()</span><span class="o">&gt;</span><span class="p">(</span><span class="n">fct</span>: <span class="nc">Fct</span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
<span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">foo3</span><span class="p">(</span><span class="n">foo2</span><span class="p">);</span><span class="w"> </span><span class="c1">// this line</span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="216600359"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216600359" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216600359">(Nov 13 2020 at 11:52)</a>:</h4>
<p>This project start to give some results: <a href="https://github.com/robinmoussu/cargo-callgraph/blob/master/test/test1/current_status.svg">generated svg</a>, generated when analyzing <a href="https://github.com/robinmoussu/cargo-callgraph/blob/master/test/test1/src/main.rs">this source file</a> (and generating <a href="https://github.com/robinmoussu/cargo-callgraph/blob/master/test/test1/current_status.dot">this intermediate graphviz file</a>). The link should be stable for some time and will be updated regularly.<br>
And the goal is to get <a href="https://github.com/robinmoussu/cargo-callgraph/blob/master/test/test1/test1.svg">this svg</a>.</p>



<a name="216600558"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216600558" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216600558">(Nov 13 2020 at 11:54)</a>:</h4>
<p>As you can see in my <a href="https://github.com/robinmoussu/cargo-callgraph/issues/1">todo list</a>, I still need to do a lot of stuff, most notably track the source of indirect call, like function pointer or trait object.</p>



<a name="216755988"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216755988" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216755988">(Nov 14 2020 at 23:24)</a>:</h4>
<p><span class="user-mention" data-user-id="281841">@Robin Moussu</span> If it helps, that's the kind of thing that some forms of devirtualization also wants to do: figure out every possible caller and callee through a given function pointer.</p>



<a name="216779842"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/216779842" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#216779842">(Nov 15 2020 at 08:49)</a>:</h4>
<p>Effectively. I will keep that in mind, but for the moment I don't think that such precision is needed.</p>
<p>For example, from this code</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">foo</span><span class="p">();</span><span class="w"></span>
<span class="k">fn</span> <span class="nf">bar</span><span class="o">&lt;</span><span class="n">Fct</span>: <span class="nb">Fn</span><span class="p">()</span><span class="o">&gt;</span><span class="p">(</span><span class="n">fct</span>: <span class="nc">Fct</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">     </span><span class="n">fct</span><span class="p">();</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
<span class="k">fn</span> <span class="nf">baz</span><span class="o">&lt;</span><span class="n">Fct</span>: <span class="nb">Fn</span><span class="p">()</span><span class="o">&gt;</span><span class="p">(</span><span class="n">fct</span>: <span class="nc">Fct</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">bar</span><span class="p">(</span><span class="n">fct</span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">baz</span><span class="p">(</span><span class="n">foo</span><span class="p">);</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>What I plan to report is that</p>
<ul>
<li><code>foo</code> doesn't have direct or indirect calee</li>
<li><code>bar</code> has  an indirect call, through a function pointer set-up in his caller <code>baz</code></li>
<li><code>baz</code> has a direct call to <code>bar</code>, and got a function pointer from its caller <code>main</code></li>
<li><code>main</code> has a direct call to <code>baz</code> and give it a function pointer to <code>foo</code></li>
</ul>
<p>Starting from <code>bar</code> it is thus still possible to find that there is a call to <code>foo</code> by looking at the source of the function pointer recursively as well as knowing that it was <code>main</code> who set-up that function pointer. But it's true that a devirtualization analysis would directly give the information <code>bar</code> is calling <code>foo</code> through a function pointer. I think that the information “that function pointer was set-up in <code>main</code>” is also useful, and I would need to propagate it with the devirtualization. I definitively keep this in mind if my current (simpler) approach give a result that is too hard to read.</p>



<a name="217015883"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/217015883" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#217015883">(Nov 17 2020 at 15:18)</a>:</h4>
<p><span class="user-mention" data-user-id="239881">@Josh Triplett</span> My naive algorithm was in fact too naive, and I will effectively need to (re)implement de-virtualization. Do you know if rustc already have a de-virtualization pass somewhere? I <code>rg</code>-ed the sources, and found occurrences of the word "devirtualization" only in <code>src/llvm-project</code>, so I assume that all de-virtualization is done on the llvm-side.</p>



<a name="217019281"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/217019281" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#217019281">(Nov 17 2020 at 15:42)</a>:</h4>
<p>There is no devirtualization done by rustc.</p>



<a name="217019403"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/217019403" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#217019403">(Nov 17 2020 at 15:43)</a>:</h4>
<p>Do you think it's a bad idea to try to implement it myself (and thus I should look how it's done in C++), or should I try to implement it in Rust?</p>



<a name="217019900"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/217019900" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#217019900">(Nov 17 2020 at 15:46)</a>:</h4>
<p>I think that this time I have a better understanding of what I need to do functionally, and it doesn't seems that complicated (once again I can be totally wrong).</p>



<a name="217020018"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/217020018" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#217020018">(Nov 17 2020 at 15:47)</a>:</h4>
<p>And while we are at it, do you know how I should write tests for this? Should I just put the code I want to analyze in a string literal, and handle it to my analysis? Or is there a better way?</p>



<a name="217020484"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/217020484" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#217020484">(Nov 17 2020 at 15:50)</a>:</h4>
<p>De-virtualization wouldn't help much at all at this stage. Other mir optimizations would need to get better first for there to be any opportunities to de-virtualization at the mir level.</p>



<a name="217020674"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/217020674" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#217020674">(Nov 17 2020 at 15:51)</a>:</h4>
<p><span class="user-mention silent" data-user-id="281841">Robin Moussu</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/Extract.20callgraph.20of.20a.20crate/near/217020018">said</a>:</p>
<blockquote>
<p>And while we are at it, do you know how I should write tests for this? Should I just put the code I want to analyze in a string literal, and handle it to my analysis? Or is there a better way?</p>
</blockquote>
<p>Rustc uses end-to-end tests for almost everything. Aka it takes a full rust file that it compiles and possibly runs. There are also several attributes that cause rustc to give error messages containing the results of certain analyses.</p>



<a name="217020768"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/217020768" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#217020768">(Nov 17 2020 at 15:52)</a>:</h4>
<p>And there are also some run-make tests which run a Makefile.</p>



<a name="217020821"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/217020821" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#217020821">(Nov 17 2020 at 15:52)</a>:</h4>
<p>Unit tests are basically only used by the standard library.</p>



<a name="217021864"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/217021864" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#217021864">(Nov 17 2020 at 16:00)</a>:</h4>
<p>I thin that I have already all the information I need in MIR:</p>
<ul>
<li>Each function call is either a direct function call, or a call through a trait object (stop me if I'm wrong).</li>
<li>For each function call, I want to track the sources of each arguments. An argument can have multiple source, for example if it is set if the if or else branch. A source is either (directly or indirectly) a constant, an argument of the function being analyzed, or the return value of another function. I will ignore control flow for this analysis.<br>
Then I <em>just</em> (<strong><em>just</em></strong>) need to aggregate this information at the whole program level, and display it in a readable manner.</li>
</ul>



<a name="217741022"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/217741022" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#217741022">(Nov 24 2020 at 11:29)</a>:</h4>
<p>If anyone is interested, here is the current status:</p>
<ul>
<li>I have a working control-flow un-aware intra function analysis that track the dependencies between all mir variables. This means that for all the arguments of a callee function I can track if the original source of that argument was from a constant, an argument (and which one) of the current function, and/or the return value of another function being called in this very function (of course multiple choice can apply at the same time for example if a value is set from two branches of a condition). This includes function pointer and trait object which is important to create an accurate call-graph.</li>
<li>I have the type of every MIR variable, especially the arguments and return value of a function.</li>
<li>I can detect if a call is direct (<code>foo()</code>), or through a trait (<code>&lt;foo as MyTrai()&gt;::my_method()</code>or <code>Fn()::call(fct_ptr)</code>).</li>
</ul>
<p>I am currently working on the inter analysis. Creating the call-graph of direct call is extremely easy, but creating the call-graph that include call to method of trait object is much harder. I think I have nearly extracted all the information I need, I just need to connect the dots!</p>
<p>Whith the information I'm extracting, I should be able to:</p>
<ul>
<li>show the call graph, both direct call, and through method of function object</li>
<li>show how to create a <code>Foo</code> from a <code>Bar</code> even if this means that you need chaining multiple function calls (given that I have the type of all arguments and return value of all function + the call graph)</li>
<li>show in which caller of the current function a function pointer or trait object have been set (this explains why the function <code>baz(...)</code> is calling <code>MyTrait::my_method(trait_object: SomeConcreteType, …)</code> because <code>trait_object</code> was set in <code>foo()</code>, and <code>foo()</code> calls <code>bar(trait_object)</code> which itself calls <code>baz(trait_object)</code>).</li>
</ul>



<a name="217910210"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/217910210" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#217910210">(Nov 25 2020 at 16:51)</a>:</h4>
<p>I am kinda stuck, I don't know how I should display the information I extracted!</p>
<p>Let's take this code as an example:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">fct</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">get_fct</span><span class="p">();</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">fct</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">forward_fct</span><span class="p">(</span><span class="n">fct</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="n">fct</span><span class="p">();</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">foo</span><span class="p">();</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">get_fct</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="nc">impl</span><span class="w"> </span><span class="nb">Fn</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">foo</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">forward_fct</span><span class="o">&lt;</span><span class="n">Fct</span>: <span class="nb">Fn</span><span class="p">()</span><span class="o">&gt;</span><span class="p">(</span><span class="n">fct</span>: <span class="nc">Fct</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">Fct</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">fct</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<ul>
<li><code>main</code> call directly <code>get_fct</code> and <code>forward_fct</code></li>
<li>the return value of <code>get_fct</code> is set from the constant <code>foo</code></li>
<li>the return value of the call to <code>get_fct</code> is assigned to the first argument of <code>forward_fct</code></li>
<li>the return value of <code>forward_fct</code> is derived from its firm argument</li>
<li>the function returned by <code>forward_fct</code> is called</li>
</ul>
<p>I have access to all the above statements, but I don't know how to draw it (with pen and paper, it's a design issue, not a tooling). <span class="user-mention" data-user-id="232545">@Joshua Nelson</span> maybe you have an idea.</p>



<a name="217911793"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/217911793" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#217911793">(Nov 25 2020 at 17:01)</a>:</h4>
<p>How do you draw this without forward_fct and only get_fct?</p>



<a name="217912071"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/217912071" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#217912071">(Nov 25 2020 at 17:03)</a>:</h4>
<p>Can talk about this with voice comm? Maybe on discord?</p>



<a name="217913127"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/217913127" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#217913127">(Nov 25 2020 at 17:11)</a>:</h4>
<p>I'm not at a computer right now, sorry</p>



<a name="217913154"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/217913154" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#217913154">(Nov 25 2020 at 17:11)</a>:</h4>
<p>don't worry ;)</p>



<a name="217913763"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/217913763" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#217913763">(Nov 25 2020 at 17:16)</a>:</h4>
<p>I would like to draw 1 "box" per function.</p>
<p>A direct call (like from <code>main</code> to <code>get_fct</code>) is very easy to represent, I just need to add an arrow between the "box" of the two functions. </p>
<p>I don't know how to give a good visualization of how callables (function pointers and trait objects) are send between functions. A callable has 3 possible source: a constant (like in <code>get_fct</code>), the argument of the current function (like in <code>forward_fct</code>) or the return of another called function (like in <code>main</code>). Each callable have 1 or more source (for example if a variable is set in two branches of an if statement). For call through callable, it's a bit hard, but I can cheat by using the fully qualified name (like <code>std::op::Fn::call(fct)</code>). However, I have no idea of how to represent the relation between the arguments / return value of the various functions.</p>



<a name="217914128"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/217914128" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#217914128">(Nov 25 2020 at 17:19)</a>:</h4>
<p>I'm quoting "box" an "arrow", because I'm not sure if it's the best possible shape.</p>
<p>Ultimately, I'd like to have some kind of "arrow" that goes from <code>foo</code> to <code>get_fct</code> to <code>main</code> to <code>forward_fct</code> to <code>main</code> to <code>std::ops::Fn::call</code>.</p>



<a name="217917184"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/217917184" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#217917184">(Nov 25 2020 at 17:43)</a>:</h4>
<p>So, the more interesting question to me is actually how to represent queries</p>



<a name="217917217"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/217917217" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#217917217">(Nov 25 2020 at 17:43)</a>:</h4>
<p>The way queries work is that there's a struct full of function pointers that by default are just unimplemented!</p>



<a name="217917290"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/217917290" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#217917290">(Nov 25 2020 at 17:44)</a>:</h4>
<p>Then you pass it to <code>fn provide</code> in a bunch of different crates, each of which provides its own function to store in the struct</p>



<a name="217917320"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/217917320" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#217917320">(Nov 25 2020 at 17:44)</a>:</h4>
<p>And then there's some magic in rustc_middle::ty::query to make it incremental IIRC</p>



<a name="217917383"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/217917383" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#217917383">(Nov 25 2020 at 17:45)</a>:</h4>
<p>It would be really cool to tie the final call to TyCtxt::query to its definition somehow</p>



<a name="217917492"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/217917492" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#217917492">(Nov 25 2020 at 17:46)</a>:</h4>
<p>Personally I don't think I would need to see all the places it went through along the way as long as I could find the start and end point</p>



<a name="217917536"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/217917536" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#217917536">(Nov 25 2020 at 17:47)</a>:</h4>
<p>As far as I understand, you are describing how the caching works in rustc, isn't it? Or did I just didn't understand what you meant by "query"?</p>



<a name="217917537"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/217917537" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#217917537">(Nov 25 2020 at 17:47)</a>:</h4>
<p>So maybe that's my suggestion: only show the caller and callee, and don't worry about how to show the function pointers for now</p>



<a name="217917568"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/217917568" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#217917568">(Nov 25 2020 at 17:47)</a>:</h4>
<p>Yes, I'm talking about how incremental compilation works in rustc</p>



<a name="217917602"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/217917602" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#217917602">(Nov 25 2020 at 17:47)</a>:</h4>
<p>Which is most of the APIs on TyCtxt, so I use them a lot and it's annoying to find them</p>



<a name="217917762"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/217917762" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#217917762">(Nov 25 2020 at 17:49)</a>:</h4>
<p>I definitively keep that in mind for later, but I don't need incremental compilation yet (I will add it as soon as I have a v0.1). You answered my question that I didn't asked yet <span aria-label="smile" class="emoji emoji-1f642" role="img" title="smile">:smile:</span></p>



<a name="217917927"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/217917927" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#217917927">(Nov 25 2020 at 17:50)</a>:</h4>
<p>I think it's related though: if you can display call graphs for queries you can display them for almost anything, I'd expect</p>



<a name="217917939"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/217917939" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#217917939">(Nov 25 2020 at 17:50)</a>:</h4>
<blockquote>
<p>only show the caller and callee, and don't worry about how to show the function pointers for now</p>
</blockquote>
<p>That's the really easy part though! The infrastructure I put in place is completely overkill for this! I have the data structure, but I really don't know what to do with it.</p>



<a name="217917974"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/217917974" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#217917974">(Nov 25 2020 at 17:51)</a>:</h4>
<p>Well, do the easy part first :P</p>



<a name="217918018"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/217918018" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#217918018">(Nov 25 2020 at 17:51)</a>:</h4>
<p>You need about 30 lines to get it!</p>



<a name="217918102"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/217918102" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#217918102">(Nov 25 2020 at 17:52)</a>:</h4>
<p>But the call-graph is highly incomplete.</p>



<a name="217921603"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/217921603" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#217921603">(Nov 25 2020 at 18:24)</a>:</h4>
<p>Maybe you could use open circles to represent a function pointer, or something like that</p>



<a name="217990691"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/217990691" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#217990691">(Nov 26 2020 at 11:27)</a>:</h4>
<p>I think I start to get <a href="/user_uploads/4715/TjWHaghp-d3jqwmMDvIAwjVL/example.svg">something nice</a>  <span aria-label="wink" class="emoji emoji-1f609" role="img" title="wink">:wink:</span>.</p>
<div class="spoiler-block"><div class="spoiler-header">
<p>graphviz code</p>
</div><div class="spoiler-content" aria-hidden="true">
<div class="codehilite" data-code-language="dot"><pre><span></span><code>digraph "crate-name" {
    node [shape=plaintext]

    subgraph cluster_01 {
        color=none

        main [
            label=&lt;&lt;font color='red'&gt;main&lt;/font&gt;( _1: &lt;font color='darkgreen'&gt;impl Fn()&lt;/font&gt;, _2: &lt;font color='darkgreen'&gt;usize&lt;/font&gt; )&gt;
        ];

        get_fct [
            label=&lt;&lt;font color='red'&gt;get_fct&lt;/font&gt;() -&amp;gt; &lt;font color='darkgreen'&gt;impl Fn()&lt;/font&gt;&gt;
        ];

        forward_fct [
            label=&lt;&lt;font color='red'&gt;forward_fct&lt;/font&gt;&amp;lt;&lt;font color='darkgreen'&gt;Fct&lt;/font&gt;: Fn()&amp;gt;( fct: &lt;font color='darkgreen'&gt;Fct&lt;/font&gt;) -&amp;gt; &lt;font color='darkgreen'&gt;Fct&lt;/font&gt;&gt;
        ];

        foo [
            label=&lt;&lt;font color='red'&gt;foo&lt;/font&gt;()&gt;
        ];

        bar [
            label=&lt;&lt;font color='red'&gt;bar&lt;/font&gt;()&gt;
        ];

        main_fn [
            label=&lt;std::ops::Fn&amp;lt;&lt;font color='darkgreen'&gt;Fct&lt;/font&gt;&amp;gt;::&lt;font color='red'&gt;call&lt;/font&gt;( fct: &lt;font color='darkgreen'&gt;Fct&lt;/font&gt;)&gt;
        ]

        main -&gt; get_fct [ dir=both color="black:purple" arrowtail=empty ]
        main -&gt; forward_fct [ dir=both color="blue:purple" arrowtail=empty ]
        get_fct -&gt; foo [ dir=back color="grey" arrowtail=empty ]
        main -&gt; main_fn [ color="blue" ]
        foo -&gt; bar
    }

    subgraph cluster_02 {
        label = "Legend";
        {
            rank=same
            key [label=&lt;&lt;table border="0" cellpadding="2" cellspacing="0" cellborder="0"&gt;
                &lt;tr&gt;&lt;td align="right" port="i1"&gt;direct call&lt;/td&gt;&lt;/tr&gt;
                &lt;tr&gt;&lt;td align="right" port="i2"&gt;return callable object&lt;/td&gt;&lt;/tr&gt;
                &lt;tr&gt;&lt;td align="right" port="i3"&gt;send callable object&lt;/td&gt;&lt;/tr&gt;
                &lt;tr&gt;&lt;td align="right" port="i4"&gt;takes reference&lt;/td&gt;&lt;/tr&gt;
                &lt;/table&gt;&gt;]
            key2 [label=&lt;&lt;table border="0" cellpadding="2" cellspacing="0" cellborder="0"&gt;
                &lt;tr&gt;&lt;td port="i1"&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
                &lt;tr&gt;&lt;td port="i2"&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
                &lt;tr&gt;&lt;td port="i3"&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
                &lt;tr&gt;&lt;td port="i4"&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
                &lt;/table&gt;&gt;]
            key:i1:e -&gt; key2:i1:w [ color=black ]
            key:i2:e -&gt; key2:i2:w [ color=purple direction=back arromtail=empty ]
            key:i3:e -&gt; key2:i3:w [ color=blue arromtail=empty ]
            key:i4:e -&gt; key2:i4:w [ color=pink direction=back arromtail=empty ]
        }
    }
}
</code></pre></div>
</div></div>
<p>This is a mock-up of what I want to be able to achieve when analyzing this:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">fct</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">get_fct</span><span class="p">();</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">fct</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">forward_fct</span><span class="p">(</span><span class="n">fct</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="n">fct</span><span class="p">();</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">foo</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">bar</span><span class="p">()</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">bar</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">get_fct</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="nc">impl</span><span class="w"> </span><span class="nb">Fn</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">foo</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">forward_fct</span><span class="o">&lt;</span><span class="n">Fct</span>: <span class="nb">Fn</span><span class="p">()</span><span class="o">&gt;</span><span class="p">(</span><span class="n">fct</span>: <span class="nc">Fct</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">Fct</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">fct</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="217990927"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/217990927" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#217990927">(Nov 26 2020 at 11:30)</a>:</h4>
<p>I get overlapping text and graphics when creating an svg:<br>
<a href="/user_uploads/4715/kwyA0Ful8fgkyK7rbnVY-33A/image.png">image.png</a></p>
<div class="message_inline_image"><a href="/user_uploads/4715/kwyA0Ful8fgkyK7rbnVY-33A/image.png" title="image.png"><img src="/user_uploads/4715/kwyA0Ful8fgkyK7rbnVY-33A/image.png"></a></div>



<a name="217994764"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/217994764" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#217994764">(Nov 26 2020 at 12:17)</a>:</h4>
<p>How do you put images inline?</p>



<a name="217994832"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/217994832" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#217994832">(Nov 26 2020 at 12:18)</a>:</h4>
<p>For me that's the reverse, I have extra spacing. What command did you use? <code>dot -Tsvg</code>?</p>



<a name="218004068"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218004068" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218004068">(Nov 26 2020 at 13:55)</a>:</h4>
<p>hmm, the color difference between 'return' and 'send callable object' is not very clear - but maybe there doesn't need to be a difference? I think 'send callable object' would work for both passing and returning it</p>



<a name="218004101"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218004101" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218004101">(Nov 26 2020 at 13:55)</a>:</h4>
<p>also the meaning of the hollow arrows is not clear to me</p>



<a name="218004383"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218004383" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218004383">(Nov 26 2020 at 13:58)</a>:</h4>
<p>I used <code>dot -Tsvg</code> and opened in firefox.</p>



<a name="218004511"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218004511" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218004511">(Nov 26 2020 at 13:59)</a>:</h4>
<p><span class="user-mention silent" data-user-id="281841">Robin Moussu</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/Extract.20callgraph.20of.20a.20crate/near/217994764">said</a>:</p>
<blockquote>
<p>How do you put images inline?</p>
</blockquote>
<p>I pasted the image from my clipboard. Websites like zulip and github automatically upload the image and paste a markdown reference to the image.</p>



<a name="218009937"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218009937" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218009937">(Nov 26 2020 at 14:51)</a>:</h4>
<blockquote>
<p>I pasted the image from my clipboard. Websites like zulip and github automatically upload the image and paste a markdown reference to the image.</p>
</blockquote>
<p>I did the same, but since it was a svg, it created a link without preview.</p>
<p><a href="/user_uploads/4715/zUNEE4nC8ccPa0xZRHe7FP8H/image.png">better render.png</a></p>
<div class="message_inline_image"><a href="/user_uploads/4715/zUNEE4nC8ccPa0xZRHe7FP8H/image.png" title="better render.png"><img src="/user_uploads/4715/zUNEE4nC8ccPa0xZRHe7FP8H/image.png"></a></div><p>A few remarks:</p>
<ul>
<li>the colors are pure placeholders, but I messed-up the legend. Now the "takes reference" is pink everywhere</li>
<li>
<p>for some reason I can't have the arrow in reverse + hollow in the legend</p>
</li>
<li>
<p>forward/full + black means direct call, no callable object send as argument</p>
</li>
<li>forward/full + blue means direct call, where callable object are send as arguments</li>
<li>backward/hollow + purple means that the return value contains a callable (it's always combined with a forward arrow)</li>
<li>backward/hollow + ping means that a reference to the function is taken</li>
</ul>
<hr>
<p>That being said, I really think that (unfortunately) I'm hitting the limit of what can be expressed in graphviz, and the inconsistencies (color, spacing, ignored attributes, …) in the rendering engines makes it unusable <span aria-label="sad" class="emoji emoji-2639" role="img" title="sad">:sad:</span> This means that I will have to build a GUI to be able to properly display the information I'm aggregating. Anyway this will allow for more flexibility, and increase the readability by making it easy to only display a small part of the graph.</p>



<a name="218010425"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218010425" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218010425">(Nov 26 2020 at 14:56)</a>:</h4>
<p>Something that I didn't managed to express was the link between the return of <code>get_fct</code> and the first argument to <code>forward_fct</code>, as well as between the return of <code>forward_fct</code> and the first argument to <code>std::ops::&lt;Fn&gt;::call()</code>. I would have like to have a "pipe" between the functions, and have the values that goes into those pipes. With a custom GUI, I should be able to do it :)</p>



<a name="218014763"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218014763" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218014763">(Nov 26 2020 at 15:36)</a>:</h4>
<p>Yeah, I made a screenshot. I assumed the problem would be browser specific.</p>



<a name="218035335"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218035335" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218035335">(Nov 26 2020 at 20:13)</a>:</h4>
<p>I was png vs svg. The svg doesn't have preview, while png has.</p>



<a name="218038034"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218038034" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218038034">(Nov 26 2020 at 21:01)</a>:</h4>
<p><a href="/user_uploads/4715/ehG5FmN-af-oG_PGs2Z01__Z/image.png">image.png</a></p>
<div class="message_inline_image"><a href="/user_uploads/4715/ehG5FmN-af-oG_PGs2Z01__Z/image.png" title="image.png"><img src="/user_uploads/4715/ehG5FmN-af-oG_PGs2Z01__Z/image.png"></a></div><p>I think I managed to get something better. Big black arrow are functions calls. I wanted to represent them as pipe, it's the best I was able to do, still with graphviz. They connect two functions (grey circles are in the caller, and whites in the callee). Thanks to this pipe analogy, I can show the whole dependency between all the variables in the graph. Here, when <code>main()</code> calls <code>get_fct()</code>, the return value of <code>get_fct</code> is <code>foo</code>, and that value is then passed (in <code>main</code>) to the first argument of <code>forward_fct</code></p>



<a name="218038267"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218038267" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218038267">(Nov 26 2020 at 21:04)</a>:</h4>
<div class="spoiler-block"><div class="spoiler-header">
<p>graphviz code</p>
</div><div class="spoiler-content" aria-hidden="true">
<p>digraph "crate-name" {<br>
    node [shape=none]<br>
    //compound=true</p>
<div class="codehilite"><pre><span></span><code>subgraph cluster_02 {
    color=grey
    main [label=&lt;&lt;table border=&quot;0&quot; cellpadding=&quot;2&quot; cellspacing=&quot;0&quot; cellborder=&quot;0&quot;&gt;&lt;tr&gt;
        &lt;td port=&quot;fct&quot;&gt;&lt;font color=&#39;red&#39;&gt;main&lt;/font&gt;&lt;/td&gt;
        &lt;td&gt;(&lt;/td&gt;
        &lt;td&gt;)&lt;/td&gt;
        &lt;/tr&gt;&lt;/table&gt;&gt;
    ];
    {
        rank=same
        &quot;main to get_fct&quot; [style=filled label=&quot;&quot;; width=0.2; height=0.2; shape=circle ]
        &quot;main to forward_fct&quot; [style=filled label=&quot;&quot;; width=0.2; height=0.2; shape=circle ]
        &quot;main to std::ops::Fn&lt;Fct&gt;::call&quot; [style=filled label=&quot;&quot;; width=0.2; height=0.2; shape=circle ]
    }
    &quot;main&quot; -&gt; &quot;main to get_fct&quot; [style=invis ]
    &quot;main&quot; -&gt; &quot;main to forward_fct&quot; [style=invis ]
    &quot;main&quot; -&gt; &quot;main to std::ops::Fn&lt;Fct&gt;::call&quot; [style=invis ]

    &quot;main to get_fct&quot; -&gt; &quot;main to forward_fct&quot; [color=blue]
    &quot;main to forward_fct&quot; -&gt; &quot;main to std::ops::Fn&lt;Fct&gt;::call&quot; [color=blue]
}

subgraph cluster_03 {
    color=grey
    rank=same

    get_fct [label=&lt;&lt;table border=&quot;0&quot; cellpadding=&quot;2&quot; cellspacing=&quot;0&quot; cellborder=&quot;0&quot;&gt;&lt;tr&gt;
        &lt;td port=&quot;fct&quot;&gt;&lt;font color=&#39;red&#39;&gt;get_fct&lt;/font&gt;&lt;/td&gt;
        &lt;td&gt;(&lt;/td&gt;
        &lt;td&gt;)&lt;/td&gt;
        &lt;td&gt;&amp;#8594;&lt;/td&gt;
        &lt;td port=&quot;0&quot;&gt;&lt;font color=&#39;darkgreen&#39;&gt;Fct&lt;/font&gt;&lt;/td&gt;
        &lt;/tr&gt;&lt;/table&gt;&gt;
    ];
    {
        rank=same
        &quot;get_fct from main&quot; [ label=&quot;&quot;; width=0.2; height=0.2; shape=circle ]
    }
    &quot;get_fct&quot; -&gt; &quot;get_fct from main&quot; [style=invis ]

    &quot;get_fct&quot;:0 -&gt; &quot;get_fct from main&quot; [color=blue]
}

subgraph cluster_04 {
    color=grey
    forward_fct [label=&lt;&lt;table border=&quot;0&quot; cellpadding=&quot;2&quot; cellspacing=&quot;0&quot; cellborder=&quot;0&quot;&gt;&lt;tr&gt;
        &lt;td port=&quot;fct&quot;&gt;&lt;font color=&#39;red&#39;&gt;forward_fct&lt;/font&gt;&lt;/td&gt;
        &lt;td&gt;&amp;lt;&lt;/td&gt;
        &lt;td&gt;&lt;font color=&#39;darkgreen&#39;&gt;Fct&lt;/font&gt;: Fn()&lt;/td&gt;
        &lt;td&gt;&amp;gt;&lt;/td&gt;
        &lt;td&gt;(&lt;/td&gt;
        &lt;td port=&quot;1&quot;&gt;fct: &lt;font color=&#39;darkgreen&#39;&gt;Fct&lt;/font&gt;&lt;/td&gt;
        &lt;td&gt;)&lt;/td&gt;
        &lt;td&gt;&amp;#8594;&lt;/td&gt;
        &lt;td port=&quot;0&quot;&gt;&lt;font color=&#39;darkgreen&#39;&gt;Fct&lt;/font&gt;&lt;/td&gt;
        &lt;/tr&gt;&lt;/table&gt;&gt;
    ];
    {
        rank=same
        &quot;forward_fct from main&quot; [ label=&quot;&quot;; width=0.2; height=0.2; shape=circle ]
    }
    &quot;forward_fct&quot; -&gt; &quot;forward_fct from main&quot; [style=invis ]

    &quot;forward_fct from main&quot; -&gt; forward_fct:1 [color=blue]
    &quot;forward_fct&quot;:0 -&gt; &quot;forward_fct from main&quot; [color=blue]
    &quot;forward_fct&quot;:1 -&gt; &quot;forward_fct&quot;:0 [color=blue]
}

subgraph cluster_05 {
    color=grey
    foo [label=&lt;&lt;table border=&quot;0&quot; cellpadding=&quot;2&quot; cellspacing=&quot;0&quot; cellborder=&quot;0&quot;&gt;&lt;tr&gt;
        &lt;td port=&quot;fct&quot;&gt;&lt;font color=&#39;red&#39;&gt;foo&lt;/font&gt;&lt;/td&gt;
        &lt;td&gt;(&lt;/td&gt;
        &lt;td&gt;)&lt;/td&gt;
        &lt;/tr&gt;&lt;/table&gt;&gt;
    ];
    {
        rank=same
        &quot;foo to bar&quot; [style=filled label=&quot;&quot;; width=0.2; height=0.2; shape=circle ]
    }
    &quot;foo&quot; -&gt; &quot;foo to bar&quot; [style=invis ]
}

subgraph cluster_06 {
    color=grey
    bar [
        label=&lt;&lt;font color=&#39;red&#39;&gt;bar&lt;/font&gt;()&gt;
    ];
    {
        rank=same
        &quot;bar from foo&quot; [ label=&quot;&quot;; width=0.2; height=0.2; shape=circle ]
    }
    &quot;bar&quot; -&gt; &quot;bar from foo&quot; [style=invis ]
}

subgraph cluster_07 {
    color=grey
    &quot;std::ops::Fn&lt;Fct&gt;::call&quot; [label=&lt;&lt;table border=&quot;0&quot; cellpadding=&quot;2&quot; cellspacing=&quot;0&quot; cellborder=&quot;0&quot;&gt;&lt;tr&gt;
        &lt;td&gt;std&lt;/td&gt;
        &lt;td&gt;::&lt;/td&gt;
        &lt;td&gt;ops&lt;/td&gt;
        &lt;td&gt;::&lt;/td&gt;
        &lt;td&gt;Fn&amp;lsaquo;&lt;font color=&#39;darkgreen&#39;&gt;Fct&lt;/font&gt;&amp;rsaquo;&lt;/td&gt;
        &lt;td&gt;::&lt;/td&gt;
        &lt;td port=&quot;fct&quot;&gt;&lt;font color=&#39;red&#39;&gt;call&lt;/font&gt;&lt;/td&gt;
        &lt;td&gt;(&lt;/td&gt;
        &lt;td port=&quot;1&quot;&gt;fct: &lt;font color=&#39;darkgreen&#39;&gt;Fct&lt;/font&gt;&lt;/td&gt;
        &lt;td&gt;)&lt;/td&gt;
        &lt;/tr&gt;&lt;/table&gt;&gt;
    ]
    {
        rank=same
        &quot;std::ops::Fn&lt;Fct&gt;::call from main&quot; [ label=&quot;&quot;; width=0.2; height=0.2; shape=circle ]
    }
    &quot;std::ops::Fn&lt;Fct&gt;::call&quot; -&gt; &quot;std::ops::Fn&lt;Fct&gt;::call from main&quot; [style=invis ]

    &quot;std::ops::Fn&lt;Fct&gt;::call from main&quot; -&gt; &quot;std::ops::Fn&lt;Fct&gt;::call&quot;:1 [color=blue]
}

&quot;main to get_fct&quot; -&gt; &quot;get_fct from main&quot; [ color=&quot;black:invis:black&quot; arrowhead=empty ]
&quot;main to forward_fct&quot; -&gt; &quot;forward_fct from main&quot; [ color=&quot;black:invis:black&quot; arrowhead=empty ]
&quot;main to std::ops::Fn&lt;Fct&gt;::call&quot; -&gt; &quot;std::ops::Fn&lt;Fct&gt;::call from main&quot; [ color=&quot;black:invis:black&quot; arrowhead=empty ]
&quot;foo to bar&quot; -&gt; &quot;bar from foo&quot; [ color=&quot;black:invis:black&quot; arrowhead=empty ]
&quot;foo&quot;:fct -&gt; &quot;get_fct&quot;:0  [ color=&quot;blue&quot; arrowtail=empty ]
</code></pre></div>

</div></div>
<p>As you can see, I can point directly to the function name, all arguments individually as well as the return type.</p>
<p>I am not yet convinced by the visual of the function call (the circle), but I like to be able to have one place per call.</p>



<a name="218038351"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218038351" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218038351">(Nov 26 2020 at 21:06)</a>:</h4>
<p>btw, I'm using <code>dot -Txlib</code> to no have spacing issues.</p>



<a name="218934975"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218934975" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218934975">(Dec 05 2020 at 13:21)</a>:</h4>
<p>For those interested to get a quick status:</p>
<ul>
<li>I started a new job this week. I didn't anticipated that I would not have enough energy to write a single line during the weekdays :(</li>
<li>DONE: extracting all function information (ie, their name, arguments, types of arguments and return type) for the function that exists in the current crate (i.e. <code>std::ops::Fn&lt;Fct&gt;::call</code> is missing)</li>
<li>DONE: extract all the caller to callee dependencies (i.e. all fat black arrows  + the grey circles + the blue arrows leaving them)</li>
<li>TODO: the caller from callee information (i.e. the white circle + the blues arrows leaving them)</li>
<li>TODO: the internals dependencies to the return type is not yet extracted (i.e. the blue arrows that goes from the arguments to the return type)</li>
<li>DONE: writing the graphviz generator (i.e. converting the internal representation to text) at the exception of coloring the generic types in green in the type of the function itself</li>
<li>TODO: understand how to call it with cargo (currently it only works with a single file.</li>
</ul>
<p>The history is an absolute mess, but you can find the code on my <a href="http://robinmoussu/cargo-callgraph.git">github</a>.</p>
<p><a href="/user_uploads/4715/wla0p_B66QBPLb7jZgMBl9T7/image.png">image.png</a></p>
<div class="message_inline_image"><a href="/user_uploads/4715/wla0p_B66QBPLb7jZgMBl9T7/image.png" title="image.png"><img src="/user_uploads/4715/wla0p_B66QBPLb7jZgMBl9T7/image.png"></a></div>



<a name="218936330"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218936330" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218936330">(Dec 05 2020 at 13:59)</a>:</h4>
<p><span class="user-mention" data-user-id="281841">@Robin Moussu</span> does that mean you won't be working on the project any more? :(</p>



<a name="218936564"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218936564" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> vn-ki <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218936564">(Dec 05 2020 at 14:05)</a>:</h4>
<p>Ngl, this would've been a very cool thing to be inside the docs</p>



<a name="218936674"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218936674" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218936674">(Dec 05 2020 at 14:09)</a>:</h4>
<p>also, is this issue up to date? <a href="https://github.com/robinmoussu/cargo-callgraph/issues/1">https://github.com/robinmoussu/cargo-callgraph/issues/1</a></p>



<a name="218938521"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218938521" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218938521">(Dec 05 2020 at 15:02)</a>:</h4>
<p>Don't, worry, I will continue, it's just that I will advance much slower :(</p>



<a name="218939157"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218939157" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218939157">(Dec 05 2020 at 15:19)</a>:</h4>
<p>I updated the issue with what I posted in this thread this morning</p>



<a name="218940082"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218940082" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218940082">(Dec 05 2020 at 15:43)</a>:</h4>
<p><span class="user-mention" data-user-id="281841">@Robin Moussu</span> are you interested in help running on multiple crates?</p>



<a name="218940084"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218940084" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218940084">(Dec 05 2020 at 15:43)</a>:</h4>
<p>not sure how much help I can be with the rest, but that sounds doable</p>



<a name="218940090"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218940090" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218940090">(Dec 05 2020 at 15:43)</a>:</h4>
<p>yes</p>



<a name="218940151"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218940151" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218940151">(Dec 05 2020 at 15:44)</a>:</h4>
<p>AFAIK you kind of touch that issue in what you did this week to have a working rustdoc compiled outside of the tree, isn't it?</p>



<a name="218940158"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218940158" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218940158">(Dec 05 2020 at 15:45)</a>:</h4>
<p>I don't think they're exactly related</p>



<a name="218940161"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218940161" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218940161">(Dec 05 2020 at 15:45)</a>:</h4>
<p>remind me how far you got? You were setting RUSTDOC=cargo-callgraph, right?</p>



<a name="218940212"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218940212" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218940212">(Dec 05 2020 at 15:46)</a>:</h4>
<p><span class="user-mention" data-user-id="281841">@Robin Moussu</span> what version of nightly are you building with? <code>rustc 1.50.0-nightly (349b3b324 2020-11-29)</code> gives errors about ForeignMod</p>



<a name="218940235"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218940235" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218940235">(Dec 05 2020 at 15:47)</a>:</h4>
<p>(this is one of the reasons rustdoc is special and not just a normal crate - it depends on internals)</p>



<a name="218940297"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218940297" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218940297">(Dec 05 2020 at 15:49)</a>:</h4>
<p>I am using rustc 1.50.0-nightly (1c389ffef 2020-11-24) (randomly chosen). Should I update it?</p>



<a name="218940299"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218940299" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218940299">(Dec 05 2020 at 15:49)</a>:</h4>
<p>nah, I'll just make a PR adding rust-toolchain</p>



<a name="218940338"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218940338" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218940338">(Dec 05 2020 at 15:50)</a>:</h4>
<blockquote>
<p>remind me how far you got? You were setting RUSTDOC=cargo-callgraph, right?</p>
</blockquote>
<p>yes</p>



<a name="218940353"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218940353" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218940353">(Dec 05 2020 at 15:51)</a>:</h4>
<p><span class="user-mention silent" data-user-id="232545">Joshua Nelson</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/Extract.20callgraph.20of.20a.20crate/near/218940299">said</a>:</p>
<blockquote>
<p>nah, I'll just make a PR adding rust-toolchain</p>
</blockquote>
<p><a href="https://rust-lang.github.io/rustup/overrides.html?highlight=toolchain#the-toolchain-file">https://rust-lang.github.io/rustup/overrides.html?highlight=toolchain#the-toolchain-file</a></p>



<a name="218940447"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218940447" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218940447">(Dec 05 2020 at 15:53)</a>:</h4>
<p>When you say "adding a PR", you mean adding the <code>rust-toolchain</code> file in my repository?</p>



<a name="218940481"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218940481" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218940481">(Dec 05 2020 at 15:54)</a>:</h4>
<p>yeah</p>



<a name="218940487"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218940487" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218940487">(Dec 05 2020 at 15:54)</a>:</h4>
<p>since otherwise it's painful to try and replicate the toolchain to build</p>



<a name="218940492"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218940492" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218940492">(Dec 05 2020 at 15:54)</a>:</h4>
<p>got it.</p>



<a name="218940503"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218940503" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218940503">(Dec 05 2020 at 15:54)</a>:</h4>
<p>hmm, now I'm getting <code>error[E0463]: can't find crate for `lazy_static` </code> - are you passing --sysroot or something?</p>



<a name="218940507"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218940507" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218940507">(Dec 05 2020 at 15:54)</a>:</h4>
<p>Which nightly should I use? Today's one?</p>



<a name="218940508"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218940508" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218940508">(Dec 05 2020 at 15:55)</a>:</h4>
<p>with <code>rustc 1.50.0-nightly (1c389ffef 2020-11-24)</code></p>



<a name="218940515"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218940515" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218940515">(Dec 05 2020 at 15:55)</a>:</h4>
<p>well the one it <em>builds</em> with</p>



<a name="218940520"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218940520" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218940520">(Dec 05 2020 at 15:55)</a>:</h4>
<p>which appears to be hard to find <span aria-label="laughing" class="emoji emoji-1f606" role="img" title="laughing">:laughing:</span></p>



<a name="218940569"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218940569" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218940569">(Dec 05 2020 at 15:56)</a>:</h4>
<p>The only thing I'm doing is literally <code>cargo run</code></p>



<a name="218940573"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218940573" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218940573">(Dec 05 2020 at 15:56)</a>:</h4>
<p>this is the error on latest nightly:</p>
<div class="codehilite"><pre><span></span><code>error[E0532]: expected tuple struct or tuple variant, found struct variant `hir::ItemKind::ForeignMod`
    --&gt; visit_ast.rs:345:13
     |
345  |             hir::ItemKind::ForeignMod(ref fm) =&gt; {
     |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |
help: use struct pattern syntax instead
     |
345  |             hir::ItemKind::ForeignMod { /* fields */ } =&gt; {
     |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: consider importing one of these items instead
     |
4    | use crate::core::resolve::ItemKind::ForeignMod;
     |
4    | use rustc_ast::ItemKind::ForeignMod;
</code></pre></div>



<a name="218940576"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218940576" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218940576">(Dec 05 2020 at 15:56)</a>:</h4>
<p>which is fine, I don't expect it to build on ever y version</p>



<a name="218940577"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218940577" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218940577">(Dec 05 2020 at 15:57)</a>:</h4>
<p>but the fact that I can't build with your exact version is concerning</p>



<a name="218940592"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218940592" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218940592">(Dec 05 2020 at 15:57)</a>:</h4>
<p>I'll just add lazy_static as a dependency for now</p>



<a name="218940712"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218940712" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218940712">(Dec 05 2020 at 16:00)</a>:</h4>
<p><code> error[E0463]: can't find crate for `rustc_ast` </code><br>
<span aria-label="face palm" class="emoji emoji-1f926" role="img" title="face palm">:face_palm:</span> I don't have rustc_dev installed</p>



<a name="218940713"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218940713" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218940713">(Dec 05 2020 at 16:00)</a>:</h4>
<p>that would do it</p>



<a name="218940735"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218940735" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218940735">(Dec 05 2020 at 16:00)</a>:</h4>
<p>btw, it's ultra-dirty, but the output filename is hardcoded  to "<a href="http://example2.dot">example2.dot</a>"</p>



<a name="218940814"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218940814" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218940814">(Dec 05 2020 at 16:02)</a>:</h4>
<p>Then I'm using <code>dot -Txlib example2.dot</code> (assuming you are on Linux, this should work).</p>



<a name="218940841"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218940841" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218940841">(Dec 05 2020 at 16:03)</a>:</h4>
<p><a href="https://github.com/robinmoussu/cargo-callgraph/pull/2">https://github.com/robinmoussu/cargo-callgraph/pull/2</a></p>



<a name="218940883"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218940883" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218940883">(Dec 05 2020 at 16:03)</a>:</h4>
<p>if you want to use <code>dot -Tsvg</code>, you must use <code>dot -Tsvg:cairo</code> otherwise there are extra white space between the colored items. <code>dot -Tpng</code> works fine.</p>



<a name="218940986"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218940986" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218940986">(Dec 05 2020 at 16:05)</a>:</h4>
<p><a href="https://github.com/robinmoussu/cargo-callgraph/pull/3">https://github.com/robinmoussu/cargo-callgraph/pull/3</a></p>



<a name="218941056"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218941056" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218941056">(Dec 05 2020 at 16:07)</a>:</h4>
<p>wow rustdoc is slow to compile even out of tree</p>



<a name="218941061"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218941061" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218941061">(Dec 05 2020 at 16:07)</a>:</h4>
<p>this is painful, maybe I'll work on that this weekend</p>



<a name="218941068"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218941068" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218941068">(Dec 05 2020 at 16:07)</a>:</h4>
<blockquote>
<p>= note: ld.lld: error: failed to open /home/joshua/.local/lib/cargo/target/debug/deps/cargo_callgraph-a798f4ebbc3fb725: No space left on device</p>
</blockquote>
<p><span aria-label="surprise" class="emoji emoji-1f62e" role="img" title="surprise">:surprise:</span></p>



<a name="218941145"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218941145" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218941145">(Dec 05 2020 at 16:09)</a>:</h4>
<blockquote>
<p>wow rustdoc is slow to compile even out of tree</p>
</blockquote>
<p>Yes, even in incremental builds. I assume it's the linking stage.</p>



<a name="218941150"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218941150" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218941150">(Dec 05 2020 at 16:09)</a>:</h4>
<p>I don't think it is, in-tree the library takes 10x as long to compile as rustdoc-tool</p>



<a name="218941383"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218941383" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218941383">(Dec 05 2020 at 16:14)</a>:</h4>
<p>also <span class="user-mention" data-user-id="281841">@Robin Moussu</span> do you want me to reply to <a href="https://github.com/rust-lang/rust/pull/78926#issuecomment-726653035">https://github.com/rust-lang/rust/pull/78926#issuecomment-726653035</a> or do you want to?</p>



<a name="218941397"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218941397" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218941397">(Dec 05 2020 at 16:15)</a>:</h4>
<p>Go for it. I wanted to contact you about this anyway</p>



<a name="218941400"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218941400" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218941400">(Dec 05 2020 at 16:15)</a>:</h4>
<p>My PR isn't needed with the work you did, isn't it?</p>



<a name="218941444"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218941444" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218941444">(Dec 05 2020 at 16:16)</a>:</h4>
<p>well, more like my change is a different approach</p>



<a name="218941452"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218941452" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218941452">(Dec 05 2020 at 16:16)</a>:</h4>
<p>yours is building out of tree with <code>rust-toolchain</code> (like cargo-callgraph), mine is building in tree and having x.py sync the versions for you</p>



<a name="218941457"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218941457" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218941457">(Dec 05 2020 at 16:16)</a>:</h4>
<p>the x.py version is more flexible in-tree but doesn't allow building out of tree</p>



<a name="218941469"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218941469" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218941469">(Dec 05 2020 at 16:17)</a>:</h4>
<p>ah, so both should be merged?</p>



<a name="218941476"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218941476" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218941476">(Dec 05 2020 at 16:17)</a>:</h4>
<p>I'm not sure it makes sense to have both if rustdoc stays in-tree</p>



<a name="218941525"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218941525" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218941525">(Dec 05 2020 at 16:18)</a>:</h4>
<p>What is the advantage of being in-tree versus being a submodule that can compile independently?</p>



<a name="218941527"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218941527" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218941527">(Dec 05 2020 at 16:18)</a>:</h4>
<blockquote>
<div class="codehilite"><pre><span></span><code>    let filename = &quot;/home/robin/dev/cargo-callgraph/example2.dot&quot;;
</code></pre></div>

</blockquote>
<p><span aria-label="angry" class="emoji emoji-1f620" role="img" title="angry">:angry:</span></p>



<a name="218941532"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218941532" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218941532">(Dec 05 2020 at 16:18)</a>:</h4>
<p><span class="user-mention silent" data-user-id="281841">Robin Moussu</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/Extract.20callgraph.20of.20a.20crate/near/218941525">said</a>:</p>
<blockquote>
<p>What is the advantage of being in-tree versus being a submodule that can compile independently?</p>
</blockquote>
<p>submodules are painful and subtree syncs are only slightly less painful</p>



<a name="218941536"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218941536" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218941536">(Dec 05 2020 at 16:18)</a>:</h4>
<p>and being out of tree means you can't modify rustc if you need to</p>



<a name="218941539"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218941539" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218941539">(Dec 05 2020 at 16:18)</a>:</h4>
<p>1) make it work<br>
2) make it right<br>
3) make it fast</p>
<p>I'm on stage 1!</p>



<a name="218941556"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218941556" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218941556">(Dec 05 2020 at 16:19)</a>:</h4>
<p>well right, but it will be a ton of work either way</p>



<a name="218941559"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218941559" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218941559">(Dec 05 2020 at 16:19)</a>:</h4>
<p>and I would rather do the 'correct' solution if I'm going to put in the time</p>



<a name="218941602"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218941602" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218941602">(Dec 05 2020 at 16:20)</a>:</h4>
<p>That's why the commits messages are mostly "wip". I'm not sure of what the architecture should be, etc…</p>



<a name="218941647"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218941647" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218941647">(Dec 05 2020 at 16:21)</a>:</h4>
<p><a href="https://github.com/robinmoussu/cargo-callgraph/pull/4">https://github.com/robinmoussu/cargo-callgraph/pull/4</a></p>



<a name="218941702"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218941702" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218941702">(Dec 05 2020 at 16:22)</a>:</h4>
<p><a href="https://github.com/robinmoussu/cargo-callgraph/issues/5">https://github.com/robinmoussu/cargo-callgraph/issues/5</a></p>



<a name="218941707"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218941707" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218941707">(Dec 05 2020 at 16:22)</a>:</h4>
<p>Lol, I realize that this was the reason it didn't seems to work in my clone in /tmp (PR#4)</p>



<a name="218941713"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218941713" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218941713">(Dec 05 2020 at 16:23)</a>:</h4>
<p>not sure what went wrong for <a href="https://github.com/rust-lang/rust/issues/5">#5</a>, something to do with callsites?</p>



<a name="218941721"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218941721" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218941721">(Dec 05 2020 at 16:23)</a>:</h4>
<p>it seems related to the algorithm, not the build process</p>



<a name="218941788"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218941788" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218941788">(Dec 05 2020 at 16:24)</a>:</h4>
<p>that's the algo. I still have too much assumption.</p>



<a name="218941796"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218941796" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218941796">(Dec 05 2020 at 16:24)</a>:</h4>
<p>anyway I have to go soon, lmk if you figure it out</p>



<a name="218941820"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218941820" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218941820">(Dec 05 2020 at 16:25)</a>:</h4>
<p>try with this input file</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">fct</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">get_fct</span><span class="p">();</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">fct</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">forward_fct</span><span class="p">(</span><span class="n">fct</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="n">fct</span><span class="p">();</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">foo</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">bar</span><span class="p">()</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">bar</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">get_fct</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="nc">impl</span><span class="w"> </span><span class="nb">Fn</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">foo</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">forward_fct</span><span class="o">&lt;</span><span class="n">Fct</span>: <span class="nb">Fn</span><span class="p">()</span><span class="o">&gt;</span><span class="p">(</span><span class="n">fct</span>: <span class="nc">Fct</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">Fct</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">fct</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="218941877"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218941877" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218941877">(Dec 05 2020 at 16:26)</a>:</h4>
<p>are you messing with RUSTFLAGS or something? Every time I <code>cargo run</code> it does a full rebuild</p>



<a name="218941895"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218941895" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218941895">(Dec 05 2020 at 16:26)</a>:</h4>
<p>oh maybe it's rust-analyzer</p>



<a name="218941898"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218941898" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218941898">(Dec 05 2020 at 16:26)</a>:</h4>
<p>no, at least not to my knowledge</p>



<a name="218941920"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218941920" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218941920">(Dec 05 2020 at 16:27)</a>:</h4>
<p>I have the nightly installed with rustup, maybe it helps?</p>



<a name="218941974"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218941974" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218941974">(Dec 05 2020 at 16:28)</a>:</h4>
<p>do you get an output?</p>



<a name="218941992"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218941992" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218941992">(Dec 05 2020 at 16:28)</a>:</h4>
<p>I mean an output file since cargo-callgraph doesn't prints anything</p>



<a name="218942088"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218942088" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218942088">(Dec 05 2020 at 16:30)</a>:</h4>
<p>oh I was on the wrong branch lol, rust-toolchain was missing</p>



<a name="218942089"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218942089" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218942089">(Dec 05 2020 at 16:30)</a>:</h4>
<p>one sec</p>



<a name="218942094"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218942094" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218942094">(Dec 05 2020 at 16:30)</a>:</h4>
<p>ah</p>



<a name="218942102"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218942102" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218942102">(Dec 05 2020 at 16:31)</a>:</h4>
<p>yes! It works :D</p>



<a name="218942106"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218942106" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218942106">(Dec 05 2020 at 16:31)</a>:</h4>
<p>good</p>



<a name="218942177"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218942177" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218942177">(Dec 05 2020 at 16:32)</a>:</h4>
<p><span class="user-mention" data-user-id="281841">@Robin Moussu</span> <code>RUSTDOC=cargo-callgraph cargo doc</code> panics for me:</p>
<div class="codehilite"><pre><span></span><code> Documenting unicode-xid v0.2.1
thread &#39;rustc&#39; panicked at &#39;could not lift for printing&#39;, compiler/rustc_middle/src/ty/print/pretty.rs:1907:1
</code></pre></div>



<a name="218942220"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218942220" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218942220">(Dec 05 2020 at 16:33)</a>:</h4>
<div class="codehilite"><pre><span></span><code> Documenting lazy_static v1.4.0
thread &#39;rustc&#39; panicked at &#39;could not lift for printing&#39;, compiler/rustc_middle/src/ty/print/pretty.rs:1907:1
stack backtrace:
   0: rust_begin_unwind
             at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/library/std/src/panicking.rs:493:5
   1: core::panicking::panic_fmt
             at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/library/core/src/panicking.rs:92:14
   2: core::option::expect_failed
             at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/library/core/src/option.rs:1260:5
   3: rustc_middle::ty::print::pretty::&lt;impl core::fmt::Display for &amp;rustc_middle::ty::consts::Const&gt;::fmt
   4: core::fmt::write
             at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/library/core/src/fmt/mod.rs:1078:17
   5: std::io::Write::write_fmt
             at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/library/std/src/io/mod.rs:1519:15
   6: cargo_callgraph::extract_dependencies::render_dependencies
             at /home/joshua/src/rust/cargo-callgraph/extract_dependencies.rs:773:25
   7: cargo_callgraph::extract_dependencies::extract_and_render_dependencies
             at /home/joshua/src/rust/cargo-callgraph/extract_dependencies.rs:657:5
   8: cargo_callgraph::core::run_global_ctxt::{{closure}}
             at /home/joshua/src/rust/cargo-callgraph/core.rs:539:27
   9: rustc_data_structures::profiling::VerboseTimingGuard::run
             at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/compiler/rustc_data_structures/src/profiling.rs:570:9
  10: rustc_session::utils::&lt;impl rustc_session::session::Session&gt;::time
             at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/compiler/rustc_session/src/utils.rs:9:9
  11: cargo_callgraph::core::run_global_ctxt
             at /home/joshua/src/rust/cargo-callgraph/core.rs:536:5
  12: cargo_callgraph::core::run_core::{{closure}}::{{closure}}::{{closure}}::{{closure}}
             at /home/joshua/src/rust/cargo-callgraph/core.rs:474:21
  13: rustc_interface::passes::QueryContext::enter::{{closure}}
             at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/compiler/rustc_interface/src/passes.rs:725:42
  14: rustc_middle::ty::context::tls::enter_context::{{closure}}
             at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/compiler/rustc_middle/src/ty/context.rs:1739:50
  15: rustc_middle::ty::context::tls::set_tlv
             at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/compiler/rustc_middle/src/ty/context.rs:1723:9
  16: rustc_middle::ty::context::tls::enter_context
             at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/compiler/rustc_middle/src/ty/context.rs:1739:9
  17: rustc_interface::passes::QueryContext::enter
             at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/compiler/rustc_interface/src/passes.rs:725:9
  18: cargo_callgraph::core::run_core::{{closure}}::{{closure}}::{{closure}}
             at /home/joshua/src/rust/cargo-callgraph/core.rs:473:17
  19: rustc_data_structures::profiling::VerboseTimingGuard::run
             at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/compiler/rustc_data_structures/src/profiling.rs:570:9
  20: rustc_session::utils::&lt;impl rustc_session::session::Session&gt;::time
             at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/compiler/rustc_session/src/utils.rs:9:9
  21: cargo_callgraph::core::run_core::{{closure}}::{{closure}}
             at /home/joshua/src/rust/cargo-callgraph/core.rs:472:46
  22: rustc_interface::queries::&lt;impl rustc_interface::interface::Compiler&gt;::enter
             at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/compiler/rustc_interface/src/queries.rs:415:19
  23: cargo_callgraph::core::run_core::{{closure}}
             at /home/joshua/src/rust/cargo-callgraph/core.rs:431:9
  24: rustc_interface::interface::create_compiler_and_run::{{closure}}
             at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/compiler/rustc_interface/src/interface.rs:196:13
  25: rustc_span::with_source_map
             at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/compiler/rustc_span/src/lib.rs:764:5
  26: rustc_interface::interface::create_compiler_and_run
             at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/compiler/rustc_interface/src/interface.rs:190:5
  27: cargo_callgraph::core::run_core
             at /home/joshua/src/rust/cargo-callgraph/core.rs:430:5
  28: cargo_callgraph::main_options
             at /home/joshua/src/rust/cargo-callgraph/lib.rs:584:53
  29: cargo_callgraph::main_args::{{closure}}
             at /home/joshua/src/rust/cargo-callgraph/lib.rs:517:17
  30: rustc_interface::util::setup_callbacks_and_run_in_thread_pool_with_globals::{{closure}}::{{closure}}
             at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/compiler/rustc_interface/src/util.rs:152:13
  31: scoped_tls::ScopedKey&lt;T&gt;::set
             at /cargo/registry/src/github.com-1ecc6299db9ec823/scoped-tls-1.0.0/src/lib.rs:137:9
  32: rustc_span::with_session_globals
             at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/compiler/rustc_span/src/lib.rs:93:5
  33: rustc_interface::util::setup_callbacks_and_run_in_thread_pool_with_globals::{{closure}}
             at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/compiler/rustc_interface/src/util.rs:150:9
  34: rustc_interface::util::scoped_thread::{{closure}}
             at /rustc/1c389ffeff814726dec325f0f2b0c99107df2673/compiler/rustc_interface/src/util.rs:125:24
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
</code></pre></div>



<a name="218942264"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218942264" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218942264">(Dec 05 2020 at 16:34)</a>:</h4>
<p>And now I'm getting</p>
<div class="codehilite"><pre><span></span><code>RUSTDOC=cargo-callgraph cargo doc
cargo-callgraph: error while loading shared libraries: libtest-5016d499037f0dbe.so: cannot open shared object file: No such file or directory
</code></pre></div>



<a name="218942283"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218942283" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218942283">(Dec 05 2020 at 16:35)</a>:</h4>
<p>are you sure you're using the same toolchain for both? that's weird</p>



<a name="218942285"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218942285" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218942285">(Dec 05 2020 at 16:35)</a>:</h4>
<p>what are you trying to document?</p>



<a name="218942287"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218942287" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218942287">(Dec 05 2020 at 16:35)</a>:</h4>
<p>I'm documenting cargo-callgraph itself</p>



<a name="218942293"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218942293" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218942293">(Dec 05 2020 at 16:35)</a>:</h4>
<p><code>test/test1</code> and cargo callgraph itself</p>



<a name="218942390"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218942390" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218942390">(Dec 05 2020 at 16:37)</a>:</h4>
<p>I don't understand what is your error. It seems that it cannot pretty print something</p>



<a name="218942438"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218942438" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218942438">(Dec 05 2020 at 16:38)</a>:</h4>
<p>are you destroying the tcx before you print things?</p>



<a name="218942443"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218942443" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218942443">(Dec 05 2020 at 16:38)</a>:</h4>
<p>that will break it, Display borrows from tcx in a lot of places</p>



<a name="218942464"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218942464" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218942464">(Dec 05 2020 at 16:39)</a>:</h4>
<p>you are already inside <code>render_dependencies</code>, this means that you already did the extraction, and the only thing done in this function is converting the extracted data into strings and writing them in a file.</p>



<a name="218942477"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218942477" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218942477">(Dec 05 2020 at 16:39)</a>:</h4>
<p>hmm, I see <code>tcx</code> in the arguments so it's still around</p>



<a name="218942478"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218942478" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218942478">(Dec 05 2020 at 16:39)</a>:</h4>
<p>weird</p>



<a name="218942540"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218942540" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218942540">(Dec 05 2020 at 16:40)</a>:</h4>
<blockquote>
<p>are you destroying the tcx before you print things?</p>
</blockquote>
<p>Maybe, I'm copying it around, not passing by reference.</p>



<a name="218942555"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218942555" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218942555">(Dec 05 2020 at 16:41)</a>:</h4>
<p>that's fine, TyCtxt is itself a reference</p>



<a name="218942570"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218942570" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218942570">(Dec 05 2020 at 16:41)</a>:</h4>
<p><a href="https://doc.rust-lang.org/nightly/nightly-rustc/src/rustc_middle/ty/context.rs.html#892-894">https://doc.rust-lang.org/nightly/nightly-rustc/src/rustc_middle/ty/context.rs.html#892-894</a></p>



<a name="218942613"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218942613" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218942613">(Dec 05 2020 at 16:42)</a>:</h4>
<p>ok, it's what I guessed</p>



<a name="218942646"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218942646" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218942646">(Dec 05 2020 at 16:43)</a>:</h4>
<p>and the whole mir is build and stored (I did not figured out how to copy the relevant part <span aria-label="stuck out tongue wink" class="emoji emoji-1f61c" role="img" title="stuck out tongue wink">:stuck_out_tongue_wink:</span> )</p>



<a name="218942689"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218942689" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218942689">(Dec 05 2020 at 16:44)</a>:</h4>
<p>it's only destroyed after the end of <code>render_dependencies()</code></p>



<a name="218942703"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218942703" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218942703">(Dec 05 2020 at 16:44)</a>:</h4>
<p>this would be so much easier if nightly rustc had debug symbols</p>



<a name="218942788"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218942788" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218942788">(Dec 05 2020 at 16:47)</a>:</h4>
<p>The line that fails is</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="n">writeln</span><span class="o">!</span><span class="p">(</span><span class="n">output</span><span class="p">,</span><span class="w"> </span><span class="s">"    </span><span class="se">\"</span><span class="s">{}</span><span class="se">\"</span><span class="s">:function -&gt; </span><span class="se">\"</span><span class="s">{} to {}</span><span class="se">\"</span><span class="s">  [ color=</span><span class="se">\"</span><span class="s">blue</span><span class="se">\"</span><span class="s"> arrowtail=empty ]"</span><span class="p">,</span><span class="w"> </span><span class="n">source_name</span><span class="p">,</span><span class="w"> </span><span class="n">caller_name</span><span class="p">,</span><span class="w"> </span><span class="n">callee_name</span><span class="p">)</span><span class="o">?</span><span class="p">;</span><span class="w"></span>
</code></pre></div>
<p>where soruce_name is a ty::Const&lt;'tcx&gt;, caller_name and callee_name the output of <code>tcx.def_path_str()</code>. I really don't understand why the write could fail</p>



<a name="218942790"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218942790" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218942790">(Dec 05 2020 at 16:47)</a>:</h4>
<p>it's this line: <a href="https://github.com/rust-lang/rust/blob/1c389ffef/compiler/rustc_middle/src/ty/print/pretty.rs#L1844">https://github.com/rust-lang/rust/blob/1c389ffef/compiler/rustc_middle/src/ty/print/pretty.rs#L1844</a></p>



<a name="218942837"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218942837" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218942837">(Dec 05 2020 at 16:48)</a>:</h4>
<p>I really don't understand what that means (details have been lost in translation!)</p>



<a name="218942842"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218942842" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218942842">(Dec 05 2020 at 16:48)</a>:</h4>
<p>What does "lift" means?</p>



<a name="218942844"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218942844" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218942844">(Dec 05 2020 at 16:48)</a>:</h4>
<p>in this context</p>



<a name="218942849"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218942849" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218942849">(Dec 05 2020 at 16:48)</a>:</h4>
<p><a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/context/trait.Lift.html">https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/context/trait.Lift.html</a></p>



<a name="218942863"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218942863" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218942863">(Dec 05 2020 at 16:49)</a>:</h4>
<p>not sure why this could fail: <a href="https://doc.rust-lang.org/nightly/nightly-rustc/src/rustc_middle/ty/context.rs.html#1609">https://doc.rust-lang.org/nightly/nightly-rustc/src/rustc_middle/ty/context.rs.html#1609</a></p>



<a name="218942876"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218942876" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218942876">(Dec 05 2020 at 16:49)</a>:</h4>
<p>so it sounds like you're trying to print a Const that hasn't been interned?</p>



<a name="218942899"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218942899" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218942899">(Dec 05 2020 at 16:50)</a>:</h4>
<p>I don't know that that means</p>



<a name="218943065"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218943065" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218943065">(Dec 05 2020 at 16:54)</a>:</h4>
<p>me neither. If you search for <code>intern</code> in <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/consts/struct.Const.html">ty::Const</a>, it seems that we can intern it, whatever that means</p>



<a name="218943097"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218943097" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218943097">(Dec 05 2020 at 16:55)</a>:</h4>
<p>I think I need to call <code>tcx.mk_const</code> <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyCtxt.html#method.mk_const">https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.TyCtxt.html#method.mk_const</a></p>



<a name="218943301"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218943301" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218943301">(Dec 05 2020 at 17:00)</a>:</h4>
<p><span class="user-mention silent" data-user-id="281841">Robin Moussu</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/Extract.20callgraph.20of.20a.20crate/near/218942264">said</a>:</p>
<blockquote>
<p>And now I'm getting</p>
<p><div class="codehilite"><pre><span></span><code>RUSTDOC=cargo-callgraph cargo doc
cargo-callgraph: error while loading shared libraries: libtest-5016d499037f0dbe.so: cannot open shared object file: No such file or directory
</code></pre></div><br>
</p>
</blockquote>
<p>Yes it was the issue, I was not using the right cargo-callgraph</p>



<a name="218943704"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218943704" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218943704">(Dec 05 2020 at 17:10)</a>:</h4>
<p>I need to go, see you later</p>



<a name="218943718"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218943718" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218943718">(Dec 05 2020 at 17:11)</a>:</h4>
<p>I'll work on compile times maybe</p>



<a name="218943720"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218943720" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218943720">(Dec 05 2020 at 17:11)</a>:</h4>
<p>oh we never worked out what to do about <a href="https://github.com/rust-lang/rust/pull/78926">https://github.com/rust-lang/rust/pull/78926</a></p>



<a name="218943729"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/218943729" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#218943729">(Dec 05 2020 at 17:11)</a>:</h4>
<p>I'll write something up, basically "this would be a good refactor but it will probably not be used by rustdoc"</p>



<a name="219027496"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/219027496" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#219027496">(Dec 06 2020 at 22:39)</a>:</h4>
<p>I got quite a lot of progress this weekend <span aria-label="tada" class="emoji emoji-1f389" role="img" title="tada">:tada:</span> Bellow, you can find what is being generated (this is completely automated)</p>
<p>The example I showed you before:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">fct</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">get_fct</span><span class="p">();</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">fct</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">forward_fct</span><span class="p">(</span><span class="n">fct</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="n">fct</span><span class="p">();</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">foo</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">bar</span><span class="p">()</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">bar</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">get_fct</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="nc">impl</span><span class="w"> </span><span class="nb">Fn</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">foo</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">forward_fct</span><span class="o">&lt;</span><span class="n">Fct</span>: <span class="nb">Fn</span><span class="p">()</span><span class="o">&gt;</span><span class="p">(</span><span class="n">fct</span>: <span class="nc">Fct</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="nc">Fct</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">fct</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p><a href="/user_uploads/4715/4W3xDY94WGf5JsbNxRmkqPRY/image.png">image.png</a> </p>
<div class="message_inline_image"><a href="/user_uploads/4715/4W3xDY94WGf5JsbNxRmkqPRY/image.png" title="image.png"><img src="/user_uploads/4715/4W3xDY94WGf5JsbNxRmkqPRY/image.png"></a></div><hr>
<p>Two implementation of factorial:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">factorial_iter</span><span class="p">(</span><span class="n">target</span>: <span class="kt">u64</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="kt">u64</span> <span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">a</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="p">;</span><span class="w"></span>

<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="k">mut</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="k">while</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">&lt;</span><span class="w"> </span><span class="n">target</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">i</span><span class="w"> </span><span class="o">+=</span><span class="w"> </span><span class="mi">1</span><span class="p">;</span><span class="w"></span>
<span class="w">        </span><span class="n">a</span><span class="w"> </span><span class="o">*=</span><span class="w"> </span><span class="n">i</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>

<span class="w">    </span><span class="n">a</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">factorial_recursive</span><span class="p">(</span><span class="n">target</span>: <span class="kt">u64</span><span class="p">)</span><span class="w"> </span>-&gt; <span class="kt">u64</span> <span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">if</span><span class="w"> </span><span class="n">target</span><span class="w"> </span><span class="o">&lt;=</span><span class="w"> </span><span class="mi">1</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="k">return</span><span class="w"> </span><span class="mi">1</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="n">target</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">factorial_recursive</span><span class="p">(</span><span class="n">target</span><span class="w"> </span><span class="o">-</span><span class="w"> </span><span class="mi">1</span><span class="p">)</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p><a href="/user_uploads/4715/uZj6l-Z3UsDae0KAsnaKQCQ3/image.png">image.png</a> </p>
<div class="message_inline_image"><a href="/user_uploads/4715/uZj6l-Z3UsDae0KAsnaKQCQ3/image.png" title="image.png"><img src="/user_uploads/4715/uZj6l-Z3UsDae0KAsnaKQCQ3/image.png"></a></div><hr>
<p>Another example with a few function pointers:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">main</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">condition</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">false</span><span class="p">;</span><span class="w"></span>
<span class="w">    </span><span class="k">if</span><span class="w"> </span><span class="n">condition</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">m1</span>::<span class="n">foo1</span><span class="p">(</span><span class="n">m2</span>::<span class="n">bar</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"> </span><span class="k">else</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">m1</span>::<span class="n">foo3</span><span class="p">(</span><span class="n">m2</span>::<span class="n">bar</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">pub</span><span class="w"> </span><span class="k">mod</span> <span class="nn">m1</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">foo1</span><span class="o">&lt;</span><span class="n">F</span>: <span class="nb">Fn</span><span class="p">()</span><span class="o">&gt;</span><span class="p">(</span><span class="n">fct</span>: <span class="nc">F</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">foo2</span><span class="p">(</span><span class="n">fct</span><span class="p">)</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="k">fn</span> <span class="nf">foo2</span><span class="o">&lt;</span><span class="n">F</span>: <span class="nb">Fn</span><span class="p">()</span><span class="o">&gt;</span><span class="p">(</span><span class="n">fct</span>: <span class="nc">F</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">fct</span><span class="p">()</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">foo3</span><span class="o">&lt;</span><span class="n">F</span>: <span class="nb">Fn</span><span class="p">()</span><span class="o">&gt;</span><span class="p">(</span><span class="n">fct</span>: <span class="nc">F</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">foo2</span><span class="p">(</span><span class="n">fct</span><span class="p">)</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>

<span class="k">pub</span><span class="w"> </span><span class="k">mod</span> <span class="nn">m2</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">bar</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">baz</span><span class="p">();</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>

<span class="w">    </span><span class="k">fn</span> <span class="nf">baz</span><span class="p">()</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">println</span><span class="o">!</span><span class="p">(</span><span class="s">"hello word"</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p><a href="/user_uploads/4715/2FU4SiqD96-wH2Ehz6oqId4A/image.png">image.png</a></p>
<div class="message_inline_image"><a href="/user_uploads/4715/2FU4SiqD96-wH2Ehz6oqId4A/image.png" title="image.png"><img src="/user_uploads/4715/2FU4SiqD96-wH2Ehz6oqId4A/image.png"></a></div><hr>
<p>I will start to investigate why <code>RUSTDOC=target/debug/cargo-callgraph cargo doc</code> doesn't work.</p>



<a name="219732701"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/219732701" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#219732701">(Dec 12 2020 at 23:01)</a>:</h4>
<p>One big advantage of finally being able to use <code>cargo doc</code> is that I can finally test the generation on non hello-word artificial rust code. And.... I need to go back to the drawing board! Tracking the dependencies between arguments and return types, as well as using nice fat arrow is just way to noisy when used with real rust code:</p>
<p><code>dot -Txlib</code>:<br>
<a href="/user_uploads/4715/dF-D3DojS54bbVb31KBVPGOY/image.png">image.png</a> </p>
<div class="message_inline_image"><a href="/user_uploads/4715/dF-D3DojS54bbVb31KBVPGOY/image.png" title="image.png"><img src="/user_uploads/4715/dF-D3DojS54bbVb31KBVPGOY/image.png"></a></div><p><code>fdb -Txlib</code>:<br>
<a href="/user_uploads/4715/zorkJapxEBo3BA-gXGparmTB/image.png">image.png</a> </p>
<div class="message_inline_image"><a href="/user_uploads/4715/zorkJapxEBo3BA-gXGparmTB/image.png" title="image.png"><img src="/user_uploads/4715/zorkJapxEBo3BA-gXGparmTB/image.png"></a></div><p>After some manual tweaking (I totally removed the blue arrows, made the black arrow thinner, remove the call-site circle, and use a different coloration for external function), the readability improved a lot:<br>
<a href="/user_uploads/4715/iQ19JdDQEXavXjJMTOg2vWB5/image.png">image.png</a> </p>
<div class="message_inline_image"><a href="/user_uploads/4715/iQ19JdDQEXavXjJMTOg2vWB5/image.png" title="image.png"><img src="/user_uploads/4715/iQ19JdDQEXavXjJMTOg2vWB5/image.png"></a></div><p>Conclusion: while tracking all dependencies between variable seems interesting, I’m not sure it’s worth it, given that it’s really hard to display correctly. In any case, I need to simplify the amount of information I want to display, if I want to be able to have something readable at larger scale.</p>



<a name="219732729"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/219732729" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#219732729">(Dec 12 2020 at 23:01)</a>:</h4>
<p>ooh I really like that third picture</p>



<a name="219761186"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/219761186" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#219761186">(Dec 13 2020 at 13:16)</a>:</h4>
<p>I tried to run it on cargo-callgraph itself just for fun (my integration test reports that I'm missing some dependencies). I've run dot with the "fdp" driver. The result looks like a simulation of a galaxy!</p>
<p><a href="/user_uploads/4715/jILGGZ3Y8ADFgq4o-LvBceM5/image.png">image.png</a> <br>
<a href="/user_uploads/4715/e5jIOMILLOJs272l8JYK7C8U/image.png">image.png</a> <br>
<a href="/user_uploads/4715/RJJ8HCxbW2QsQbZBaHpqth1S/image.png">image.png</a> <br>
<a href="/user_uploads/4715/6YDFbs_t05mRuyclWxbQJJr1/image.png">image.png</a> </p>
<div class="message_inline_image"><a href="/user_uploads/4715/jILGGZ3Y8ADFgq4o-LvBceM5/image.png" title="image.png"><img src="/user_uploads/4715/jILGGZ3Y8ADFgq4o-LvBceM5/image.png"></a></div><div class="message_inline_image"><a href="/user_uploads/4715/e5jIOMILLOJs272l8JYK7C8U/image.png" title="image.png"><img src="/user_uploads/4715/e5jIOMILLOJs272l8JYK7C8U/image.png"></a></div><div class="message_inline_image"><a href="/user_uploads/4715/RJJ8HCxbW2QsQbZBaHpqth1S/image.png" title="image.png"><img src="/user_uploads/4715/RJJ8HCxbW2QsQbZBaHpqth1S/image.png"></a></div><div class="message_inline_image"><a href="/user_uploads/4715/6YDFbs_t05mRuyclWxbQJJr1/image.png" title="image.png"><img src="/user_uploads/4715/6YDFbs_t05mRuyclWxbQJJr1/image.png"></a></div><p><span aria-label="star" class="emoji emoji-2b50" role="img" title="star">:star:</span> <span aria-label="telescope" class="emoji emoji-1f52d" role="img" title="telescope">:telescope:</span> <span aria-label="rocket" class="emoji emoji-1f680" role="img" title="rocket">:rocket:</span></p>



<a name="219762064"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/219762064" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#219762064">(Dec 13 2020 at 13:43)</a>:</h4>
<p>Oh my goodness</p>



<a name="219762104"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/219762104" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#219762104">(Dec 13 2020 at 13:44)</a>:</h4>
<p>Can you send SVGs of those? If you zoom in are they actually useful?</p>



<a name="219762141"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/219762141" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#219762141">(Dec 13 2020 at 13:45)</a>:</h4>
<p>I'd love to use this on rustdoc itself at some point and I expect the callgraphs for cargo-callgraph and rustdoc are mostly the same</p>



<a name="219765438"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/219765438" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#219765438">(Dec 13 2020 at 15:10)</a>:</h4>
<p>If not for all the lines all over the place, it looks good <span aria-label="telescope" class="emoji emoji-1f52d" role="img" title="telescope">:telescope:</span></p>



<a name="219765474"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/219765474" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#219765474">(Dec 13 2020 at 15:11)</a>:</h4>
<p>In fact, I'm starting to think that a static SVG file might not be too helpful when the code is too complex and very interconnected, because I don't know how one could solve the problem with those lines</p>



<a name="219765555"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/219765555" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#219765555">(Dec 13 2020 at 15:13)</a>:</h4>
<p>I don't really know enough about SVG, but maybe it's possible to generate an SVG file with graphviz and add a JS layer on top to allow for searching a specific node and visualizing all of its connections?</p>



<a name="219765618"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/219765618" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#219765618">(Dec 13 2020 at 15:15)</a>:</h4>
<p>Though IIUC these graphs make it pretty clear what the entry and the leaf functions are</p>



<a name="219765686"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/219765686" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#219765686">(Dec 13 2020 at 15:16)</a>:</h4>
<p>I would want this for "what functions does resolve_str_path_error actually call"</p>



<a name="219765692"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/219765692" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#219765692">(Dec 13 2020 at 15:16)</a>:</h4>
<p>Which is not a question I currently know how to answer without reading the code for a good half hour</p>



<a name="219765697"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/219765697" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#219765697">(Dec 13 2020 at 15:16)</a>:</h4>
<p>So I guess that search would be really useful, yeah</p>



<a name="219765704"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/219765704" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#219765704">(Dec 13 2020 at 15:17)</a>:</h4>
<p>Another thing that would be useful is grouping the functions by module so you can kind of see similar ones together</p>



<a name="219765707"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/219765707" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#219765707">(Dec 13 2020 at 15:17)</a>:</h4>
<p>And maybe by crate too</p>



<a name="219765789"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/219765789" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Léo Lanteri Thauvin <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#219765789">(Dec 13 2020 at 15:19)</a>:</h4>
<p><a href="https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model#SVG_interfaces">https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model#SVG_interfaces</a> :)</p>



<a name="219784441"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/219784441" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#219784441">(Dec 13 2020 at 22:12)</a>:</h4>
<p>Zulip has been very mean today. I checked a few times, and so no response, even after refreshing the page… Anyway!</p>



<a name="219785253"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/219785253" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#219785253">(Dec 13 2020 at 22:30)</a>:</h4>
<blockquote>
<p>I'd love to use this on rustdoc itself at some point and I expect the callgraphs for cargo-callgraph and rustdoc are mostly the same</p>
</blockquote>
<p>Yes, definitively, I have one extra file, and I modified <code>core.rs</code> and <code>lib.rs</code>, that's all.</p>
<blockquote>
<p>Can you send SVGs of those? If you zoom in are they actually useful?</p>
</blockquote>
<p>You should be able to re-generates them easily (<a href="https://github.com/robinmoussu/cargo-callgraph/">git</a>). I updated the Readme, it should be easy to do it now. I could paste them, but they are (using <code>dot</code> or <code>fdp</code>) 13 and 9.9MB. And they are as unreadable as seen in the screenshot!</p>
<blockquote>
<p>I don't really know enough about SVG, but maybe it's possible to generate an SVG file with graphviz and add a JS layer on top to allow for searching a specific node and visualizing all of its connections?</p>
</blockquote>
<p>I'm not even sure that graphviz is the right solution at all. I'm using it for the moment, because it's a very good proxy for a GUI that I didn't have to write. I also think that interactivity is going to be crucial to deliver a good user experience.</p>
<blockquote>
<p>Though IIUC these graphs make it pretty clear what the entry and the leaf functions are</p>
</blockquote>
<p>Not exactly, some function (like <code>Fn::call</code> or <code>Deref::deref</code>) are absolutely over-represented, and should be hidden.</p>
<blockquote>
<p>Which is not a question I currently know how to answer without reading the code for a good half hour</p>
</blockquote>
<p>The infrastructure is nearly ready for that! AFAIK, the only dependency information I'm not extracting are global variable (thread local, static, const, …). After that, I just need to be able to propagate the local dependency information between all the functions (because of call through <code>Fn()::call</code> or other traits) that are not visible in the direct call-graph. Note that this dependency propagation could easily include the value of any variable, not only the callgraph.</p>
<blockquote>
<p>Another thing that would be useful is grouping the functions by module so you can kind of see similar ones together</p>
</blockquote>
<p>I think I will just use a different color for each module in the background of each function <span aria-label="smile" class="emoji emoji-1f642" role="img" title="smile">:smile:</span> </p>
<p>And I also nearly have all the information to be able to compute that given a <code>Foo</code> and a <code>Bar</code>, if you add a <code>Baz</code>, you could do <code>f1(Foo, Bar).f2(baz).f3()</code> to create a <code>FooBar</code>.</p>



<a name="219793016"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/219793016" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#219793016">(Dec 14 2020 at 01:57)</a>:</h4>
<blockquote>
<p>And I also nearly have all the information to be able to compute that given a <code>Foo</code> and a <code>Bar</code>, if you add a <code>Baz</code>, you could do <code>f1(Foo, Bar).f2(baz).f3()</code> to create a <code>FooBar</code>.</p>
</blockquote>
<p>Hmm, what do you  mean by that?</p>



<a name="219793124"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/219793124" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#219793124">(Dec 14 2020 at 02:00)</a>:</h4>
<blockquote>
<p>I'm not even sure that graphviz is the right solution at all. I'm using it for the moment, because it's a very good proxy for a GUI that I didn't have to write. I also think that interactivity is going to be crucial to deliver a good user experience.</p>
</blockquote>
<p>You might want to do something like <a href="https://internals.rust-lang.org/t/exploring-crate-graph-build-times-with-cargo-build-ztimings/10975"><code>-Z timings</code></a>, where you generate a static HTML file that contains the data and JS to make it interactive.</p>



<a name="219830602"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/219830602" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#219830602">(Dec 14 2020 at 11:55)</a>:</h4>
<blockquote>
<p>And I also nearly have all the information to be able to compute that given a Foo and a Bar, if you add a Baz, you could do f1(Foo, Bar).f2(baz).f3() to create a FooBar.</p>
</blockquote>
<p>When I want to create a <code>FooBar</code>, currently, the only thing I can do is to use the search function on the rustdoc generated pages for <code>FooBar</code>, and look in the <code>Return types</code> tab. It works well if you are looking for a function that directly generate a <code>FooBar</code>, but it totally fails when you need to chain multiple functions. I would like to have a tool that show me all chains of functions that lead to the creation of <code>FooBar</code>, as well as being able to filter all the input types used in those function chain.</p>



<a name="219830915"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/219830915" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Robin Moussu <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#219830915">(Dec 14 2020 at 11:58)</a>:</h4>
<blockquote>
<p>You might want to do something like -Z timings, where you generate a static HTML file that contains the data and JS to make it interactive.</p>
</blockquote>
<p>I will need to do some testing, and I’m not sure it will work. The hard part is the routing (placing the functions on the screen and choosing a somewhat optimal path for the arrows), and I’m not sure that js is fast enough to deliver a good user experience. Generating the <code>dot</code> file takes a few seconds, while generating the <code>.svg</code> with graphviz takes minutes. I don’t expect js to be so much more efficient than graphviz. I will probably have to test webassembly and write something GPU accelerated in Rust!</p>



<a name="219895123"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/219895123" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#219895123">(Dec 14 2020 at 20:06)</a>:</h4>
<blockquote>
<p>I would like to have a tool that show me all chains of functions that lead to the creation of <code>FooBar</code>, as well as being able to filter all the input types used in those function chain.</p>
</blockquote>
<p>That's cool! :)</p>



<a name="219895355"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/219895355" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#219895355">(Dec 14 2020 at 20:09)</a>:</h4>
<p>I think the reason GraphViz takes so long is that it's laying out the entire graph. Perhaps with your tool, the JS would only lay out the part of the graph you're looking at (and have everything position relative to that) so that the cost is amortized. And when you first open it up, it will focus on <code>main()</code> for a binary or just ask you what you would like to look at first?</p>



<a name="219895359"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Extract%20callgraph%20of%20a%20crate/near/219895359" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Extract.20callgraph.20of.20a.20crate.html#219895359">(Dec 14 2020 at 20:09)</a>:</h4>
<p>I'm really excited to see this tool :)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>